Skip to content
Merged

Mcp #32

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions codetide/agents/tide/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from ...autocomplete import AutoComplete
from .models import Steps
from .prompts import (
AGENT_TIDE_SYSTEM_PROMPT, CALMNESS_SYSTEM_PROMPT, GET_CODE_IDENTIFIERS_SYSTEM_PROMPT, README_CONTEXT_PROMPT, REJECT_PATCH_FEEDBACK_TEMPLATE,
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,
REPO_TREE_CONTEXT_PROMPT, STAGED_DIFFS_TEMPLATE, STEPS_SYSTEM_PROMPT, WRITE_PATCH_SYSTEM_PROMPT
)
from .utils import delete_file, parse_blocks, parse_steps_markdown, trim_to_patch_section
Expand Down Expand Up @@ -70,6 +70,8 @@ def pass_custom_logger_fn(self)->Self:
async def get_repo_tree_from_user_prompt(self, history :list)->str:

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

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

results = await codeSearch.search_smart(history_str, top_k=5)
results = await codeSearch.search_smart(history_str, top_k=15)

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

Expand Down
2 changes: 1 addition & 1 deletion codetide/agents/tide/ui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ async def agent_loop(message: Optional[cl.Message]=None, codeIdentifiers: Option
MarkerConfig(
begin_marker="*** Begin Patch",
end_marker="*** End Patch",
start_wrapper="\n```shell\n",
start_wrapper="\n```diff\n",
end_wrapper="\n```\n",
target_step=diff_step
),
Expand Down
32 changes: 32 additions & 0 deletions codetide/mcp/tools/search_code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import asyncio
from typing import List, Dict, Any
from codetide.mcp.server import codeTideMCPServer, initCodeTide
from codetide.search.code_search import SmartCodeSearch

@codeTideMCPServer.tool(
name="searchCode",
description="Perform a smart search over the codebase. Returns the most relevant code files and elements for a given query."
)
async def search_code_tool(query: str, top_k: int = 10) -> List[Dict[str, Any]]:
"""
INSTRUCTION FOR AGENT:
Use this tool to perform a smart search over the codebase for any code-related query (e.g., function, class, or concept).
- Call this tool with a natural language search query and (optionally) the number of top results to return (default: 10).
- The tool will automatically initialize the codebase context.
- It returns a list of the most relevant code elements, each as a dictionary with:
- 'doc_key': the file path or identifier of the code element
- 'score': the relevance score
- 'context': a code snippet or summary for that result
- Use this tool when you need to locate where a concept, function, or class is defined or discussed in the codebase.
"""
tide = await initCodeTide()
nodes_dict = tide.codebase.compile_tree_nodes_dict()
documents = {
filepath: "\n".join([filepath] + elements).strip()
for filepath, elements in nodes_dict.items()
if (elements and len(elements) > 0)
}
code_search = SmartCodeSearch(documents=documents)
await code_search.initialize_async()
results = await code_search.search_with_context(query, top_k=top_k)
return results
2 changes: 1 addition & 1 deletion examples/hf_demo_space/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ async def agent_loop(message: Optional[cl.Message]=None, codeIdentifiers: Option
MarkerConfig(
begin_marker="*** Begin Patch",
end_marker="*** End Patch",
start_wrapper="\n```shell\n",
start_wrapper="\n```diff\n",
end_wrapper="\n```\n",
target_step=diff_step
),
Expand Down