Skip to content

Commit 6617daa

Browse files
committed
Refactor code structure for improved readability and maintainability
1 parent 9f0bfec commit 6617daa

File tree

9 files changed

+634
-86
lines changed

9 files changed

+634
-86
lines changed

.well-known/mcp.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"$schema": "https://modelcontextprotocol.io/schemas/mcp.json",
3+
"mcpServers": {
4+
"code-index": {
5+
"command": "uv",
6+
"args": [
7+
"run",
8+
"code-index-mcp"
9+
],
10+
"transport": {
11+
"type": "stdio"
12+
},
13+
"metadata": {
14+
"name": "Code Index MCP",
15+
"description": "Local code-aware MCP server with project indexing, search, and file tools.",
16+
"homepage": "https://github.com/johnhuang316/code-index-mcp",
17+
"capabilities": [
18+
"code-search",
19+
"symbol-indexing",
20+
"file-system"
21+
]
22+
}
23+
}
24+
},
25+
"llmfeed_extension": {
26+
"path": ".well-known/mcp.llmfeed.json"
27+
}
28+
}

.well-known/mcp.llmfeed.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"$schema": "https://modelcontextprotocol.io/schemas/mcp-llmfeed.json",
3+
"feed_type": "mcp_server_list",
4+
"servers": [
5+
{
6+
"id": "code-index",
7+
"name": "Code Index MCP",
8+
"description": "Exposes project-aware indexing, search, and file utilities for LLM agents via MCP transports.",
9+
"version": "2.8.1",
10+
"transport": "stdio",
11+
"command": "uv",
12+
"args": [
13+
"run",
14+
"code-index-mcp"
15+
],
16+
"links": {
17+
"documentation": "https://github.com/johnhuang316/code-index-mcp#readme",
18+
"source": "https://github.com/johnhuang316/code-index-mcp"
19+
},
20+
"capabilities": [
21+
"code-search",
22+
"symbol-indexing",
23+
"file-system"
24+
],
25+
"tags": [
26+
"fastmcp",
27+
"code-intelligence",
28+
"watcher"
29+
]
30+
}
31+
]
32+
}

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,21 @@ Linux and macOS already expose the required XDG paths and `HOME`, so you can usu
8787
table there.
8888
Add overrides only if you run the CLI inside a restricted container.
8989

90+
### FastMCP & Discovery Manifests
91+
92+
- Run `fastmcp run fastmcp.json` to launch the server via [FastMCP](https://fastmcp.wiki/) with
93+
the correct source entrypoint and dependency metadata. Pass `--project-path` (or call the
94+
`set_project_path` tool after startup) so the index boots against the right repository.
95+
- Serve or copy `.well-known/mcp.json` to share a standards-compliant MCP manifest. Clients that
96+
support the `.well-known` convention (e.g., Claude Desktop, Codex CLI) can import this file
97+
directly instead of crafting configs manually.
98+
- Publish `.well-known/mcp.llmfeed.json` when you want to expose the richer LLM Feed metadata.
99+
It references the same `code-index` server definition plus documentation/source links, which
100+
helps registries present descriptions, tags, and capabilities automatically.
101+
102+
When sharing the manifests, remind consumers to supply `--project-path` (or to call
103+
`set_project_path`) so the server indexes the intended repository.
104+
90105
## Typical Use Cases
91106

92107
**Code Review**: "Find all places using the old API"

fastmcp.json

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"$schema": "https://fastmcp.wiki/en/schemas/fastmcp.json",
3+
"name": "Code Index MCP",
4+
"description": "Indexes a local repository and exposes search, indexing, and file utilities via the Model Context Protocol.",
5+
"license": "MIT",
6+
"keywords": [
7+
"mcp",
8+
"code-index",
9+
"search",
10+
"fastmcp"
11+
],
12+
"links": [
13+
{
14+
"rel": "source",
15+
"href": "https://github.com/johnhuang316/code-index-mcp"
16+
},
17+
{
18+
"rel": "documentation",
19+
"href": "https://github.com/johnhuang316/code-index-mcp#readme"
20+
}
21+
],
22+
"source": {
23+
"path": "src/code_index_mcp/server.py",
24+
"entrypoint": "mcp"
25+
},
26+
"environment": {
27+
"python": ">=3.10",
28+
"dependencies": [
29+
"mcp>=1.21.0,<2.0.0",
30+
"watchdog>=3.0.0",
31+
"tree-sitter>=0.20.0",
32+
"tree-sitter-javascript>=0.20.0",
33+
"tree-sitter-typescript>=0.20.0",
34+
"tree-sitter-java>=0.20.0",
35+
"tree-sitter-zig>=0.20.0",
36+
"pathspec>=0.12.1",
37+
"msgpack>=1.0.0"
38+
]
39+
},
40+
"deployment": {
41+
"transport": "stdio"
42+
}
43+
}

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ authors = [
1313
{name = "johnhuang316"}
1414
]
1515
dependencies = [
16-
"mcp>=0.3.0",
16+
"mcp>=1.21.0,<2.0.0",
1717
"watchdog>=3.0.0",
1818
"tree-sitter>=0.20.0",
1919
"tree-sitter-javascript>=0.20.0",

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
mcp>=0.3.0
1+
mcp>=1.21.0,<2.0.0
22
watchdog>=3.0.0
33
protobuf>=4.21.0
44
tree-sitter>=0.20.0

src/code_index_mcp/server.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,16 +130,14 @@ async def indexer_lifespan(_server: FastMCP) -> AsyncIterator[CodeIndexerContext
130130

131131
@mcp.resource("config://code-indexer")
132132
@handle_mcp_resource_errors
133-
def get_config() -> str:
133+
def get_config(ctx: Context) -> str:
134134
"""Get the current configuration of the Code Indexer."""
135-
ctx = mcp.get_context()
136135
return ProjectManagementService(ctx).get_project_config()
137136

138137
@mcp.resource("files://{file_path}")
139138
@handle_mcp_resource_errors
140-
def get_file_content(file_path: str) -> str:
139+
def get_file_content(file_path: str, ctx: Context) -> str:
141140
"""Get the content of a specific file."""
142-
ctx = mcp.get_context()
143141
# Use FileService for simple file reading - this is appropriate for a resource
144142
return FileService(ctx).get_file_content(file_path)
145143

src/code_index_mcp/utils/error_handler.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ def handle_mcp_resource_errors(func: Callable) -> Callable:
7676
Example:
7777
@mcp.resource("config://code-indexer")
7878
@handle_mcp_resource_errors
79-
def get_config() -> str:
80-
ctx = mcp.get_context()
79+
def get_config(ctx: Context) -> str:
8180
from ..services.project_management_service import ProjectManagementService
8281
return ProjectManagementService(ctx).get_project_config()
8382
"""

0 commit comments

Comments
 (0)