Skip to content
Open
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
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ The daemon idle-exits after `daemon.idle_timeout_minutes` (default 180, 0 = neve

**`settings.py`** — YAML config loading for both global (`~/.cocoindex_code/global_settings.yml`) and per-project (`.cocoindex_code/settings.yml`) settings. Also provides all path helpers (`cocoindex_db_path`, `target_sqlite_db_path`, `resolve_db_dir`, etc.) and host-path-mapping logic for Docker.

**`server.py`** — FastMCP wrapper that delegates `search` calls to the daemon client. Also contains the legacy `main()` entry point (`cocoindex-code` command) for backward-compatible env-var-based configuration.
**`server.py`** — MCPServer wrapper that delegates `search` calls to the daemon client. Also contains the legacy `main()` entry point (`cocoindex-code` command) for backward-compatible env-var-based configuration.

**`cli.py`** — Typer app with `ccc` subcommands (`init`, `index`, `search`, `grep`, `status`, `reset`, `doctor`, `mcp`, `daemon status/restart/stop`). CLI logic only — delegates to `client.py` or `grep.py`.

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ classifiers = [
]

dependencies = [
"mcp>=1.0.0",
"mcp>=2.0.0,<3",
"cocoindex[litellm]>=1.0.13,<1.1.0",
"sqlite-vec>=0.1.0",
"pydantic>=2.0.0",
Expand Down
8 changes: 4 additions & 4 deletions src/cocoindex_code/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import os
from pathlib import Path

from mcp.server.fastmcp import FastMCP
from mcp.server.mcpserver import MCPServer
from pydantic import BaseModel, Field

from .settings import DaemonSettings, load_user_settings
Expand Down Expand Up @@ -58,9 +58,9 @@ class SearchResultModel(BaseModel):
# === Daemon-backed MCP server factory ===


def create_mcp_server(project_root: str) -> FastMCP:
def create_mcp_server(project_root: str) -> MCPServer:
"""Create a lightweight MCP server that delegates to the daemon."""
mcp = FastMCP("cocoindex-code", instructions=_MCP_INSTRUCTIONS)
mcp = MCPServer("cocoindex-code", instructions=_MCP_INSTRUCTIONS)

@mcp.tool(
name="search",
Expand Down Expand Up @@ -201,7 +201,7 @@ async def run_heartbeat_loop() -> None:


# Keep the old `mcp` global for backward compatibility in __init__.py
mcp: FastMCP | None = None
mcp: MCPServer | None = None


# === Backward-compatible entry point ===
Expand Down
31 changes: 31 additions & 0 deletions tests/test_server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import pytest
from mcp import Client

from cocoindex_code import client as daemon_client
from cocoindex_code.protocol import SearchResponse
from cocoindex_code.server import create_mcp_server


async def test_mcp_server_uses_v2_protocol(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(
daemon_client,
"search",
lambda **kwargs: SearchResponse(success=True, offset=kwargs["offset"]),
)

server = create_mcp_server(".")
async with Client(server, raise_exceptions=True) as client:
tools = await client.list_tools()
result = await client.call_tool(
"search",
{"query": "authentication", "refresh_index": False},
)

assert [tool.name for tool in tools.tools] == ["search"]
assert result.structured_content == {
"success": True,
"results": [],
"total_returned": 0,
"offset": 0,
"message": None,
}
96 changes: 68 additions & 28 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.