Skip to content

Commit 6c490c7

Browse files
authored
Merge pull request #32 from BrunoV21/mcp
Mcp
2 parents c55de17 + 13471a9 commit 6c490c7

4 files changed

Lines changed: 38 additions & 4 deletions

File tree

codetide/agents/tide/agent.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from ...autocomplete import AutoComplete
77
from .models import Steps
88
from .prompts import (
9-
AGENT_TIDE_SYSTEM_PROMPT, CALMNESS_SYSTEM_PROMPT, GET_CODE_IDENTIFIERS_SYSTEM_PROMPT, README_CONTEXT_PROMPT, REJECT_PATCH_FEEDBACK_TEMPLATE,
9+
AGENT_TIDE_SYSTEM_PROMPT, CALMNESS_SYSTEM_PROMPT, CMD_BRAINSTORM_PROMPT, CMD_CODE_REVIEW_PROMPT, CMD_TRIGGER_PLANNING_STEPS, CMD_WRITE_TESTS_PROMPT, GET_CODE_IDENTIFIERS_SYSTEM_PROMPT, README_CONTEXT_PROMPT, REJECT_PATCH_FEEDBACK_TEMPLATE,
1010
REPO_TREE_CONTEXT_PROMPT, STAGED_DIFFS_TEMPLATE, STEPS_SYSTEM_PROMPT, WRITE_PATCH_SYSTEM_PROMPT
1111
)
1212
from .utils import delete_file, parse_blocks, parse_steps_markdown, trim_to_patch_section
@@ -70,6 +70,8 @@ def pass_custom_logger_fn(self)->Self:
7070
async def get_repo_tree_from_user_prompt(self, history :list)->str:
7171

7272
history_str = "\n\n".join([str(entry) for entry in history])
73+
for CMD_PROMPT in [CMD_TRIGGER_PLANNING_STEPS, CMD_WRITE_TESTS_PROMPT, CMD_BRAINSTORM_PROMPT, CMD_CODE_REVIEW_PROMPT]:
74+
history_str.replace(CMD_PROMPT, "")
7375
### TODO evalutate sending last N messages and giving more importance to
7476
### search results from latter messages
7577

@@ -82,7 +84,7 @@ async def get_repo_tree_from_user_prompt(self, history :list)->str:
8284
codeSearch = SmartCodeSearch(documents=nodes_dict)
8385
await codeSearch.initialize_async()
8486

85-
results = await codeSearch.search_smart(history_str, top_k=5)
87+
results = await codeSearch.search_smart(history_str, top_k=15)
8688

8789
self.tide.codebase._build_tree_dict([doc_key for doc_key,_ in results] or None)
8890

codetide/agents/tide/ui/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ async def agent_loop(message: Optional[cl.Message]=None, codeIdentifiers: Option
307307
MarkerConfig(
308308
begin_marker="*** Begin Patch",
309309
end_marker="*** End Patch",
310-
start_wrapper="\n```shell\n",
310+
start_wrapper="\n```diff\n",
311311
end_wrapper="\n```\n",
312312
target_step=diff_step
313313
),

codetide/mcp/tools/search_code.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import asyncio
2+
from typing import List, Dict, Any
3+
from codetide.mcp.server import codeTideMCPServer, initCodeTide
4+
from codetide.search.code_search import SmartCodeSearch
5+
6+
@codeTideMCPServer.tool(
7+
name="searchCode",
8+
description="Perform a smart search over the codebase. Returns the most relevant code files and elements for a given query."
9+
)
10+
async def search_code_tool(query: str, top_k: int = 10) -> List[Dict[str, Any]]:
11+
"""
12+
INSTRUCTION FOR AGENT:
13+
Use this tool to perform a smart search over the codebase for any code-related query (e.g., function, class, or concept).
14+
- Call this tool with a natural language search query and (optionally) the number of top results to return (default: 10).
15+
- The tool will automatically initialize the codebase context.
16+
- It returns a list of the most relevant code elements, each as a dictionary with:
17+
- 'doc_key': the file path or identifier of the code element
18+
- 'score': the relevance score
19+
- 'context': a code snippet or summary for that result
20+
- Use this tool when you need to locate where a concept, function, or class is defined or discussed in the codebase.
21+
"""
22+
tide = await initCodeTide()
23+
nodes_dict = tide.codebase.compile_tree_nodes_dict()
24+
documents = {
25+
filepath: "\n".join([filepath] + elements).strip()
26+
for filepath, elements in nodes_dict.items()
27+
if (elements and len(elements) > 0)
28+
}
29+
code_search = SmartCodeSearch(documents=documents)
30+
await code_search.initialize_async()
31+
results = await code_search.search_with_context(query, top_k=top_k)
32+
return results

examples/hf_demo_space/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ async def agent_loop(message: Optional[cl.Message]=None, codeIdentifiers: Option
347347
MarkerConfig(
348348
begin_marker="*** Begin Patch",
349349
end_marker="*** End Patch",
350-
start_wrapper="\n```shell\n",
350+
start_wrapper="\n```diff\n",
351351
end_wrapper="\n```\n",
352352
target_step=diff_step
353353
),

0 commit comments

Comments
 (0)