Skip to content

Commit d1cfc6d

Browse files
Adding src files with ast-grep tool support
1 parent b2c0007 commit d1cfc6d

File tree

9 files changed

+755
-0
lines changed

9 files changed

+755
-0
lines changed

src/__init__.py

Whitespace-only changes.

src/resources/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"""Resource implementations for the MCP server."""
2+
3+
# This file makes the resources directory a proper Python package.
4+
# It can be used to export specific resources if needed.

src/resources/status.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
"""System status resource for the MCP server."""
2+
3+
from typing import Dict, Any
4+
5+
def register_status_resource(mcp):
6+
"""Register the system status resource with the MCP server."""
7+
8+
@mcp.resource("system://status")
9+
async def get_system_status() -> Dict[str, Any]:
10+
"""
11+
Provide system status information about the Code Analysis MCP server.
12+
13+
Returns:
14+
Status information including version details
15+
"""
16+
try:
17+
import ast_grep_py
18+
import fastmcp
19+
20+
# Get version information
21+
ast_grep_version = getattr(ast_grep_py, "__version__", "unknown")
22+
fastmcp_version = getattr(fastmcp, "__version__", "unknown")
23+
24+
# Get available tools
25+
available_tools = {
26+
"ast_grep": [
27+
"ast_grep_parse_code",
28+
"ast_grep_find_pattern",
29+
"ast_grep_replace_pattern",
30+
"ast_grep_run_yaml_rule"
31+
]
32+
# Future tools will be added here
33+
}
34+
35+
return {
36+
"status": "operational",
37+
"ast_grep_py_version": ast_grep_version,
38+
"fastmcp_version": fastmcp_version,
39+
"supported_languages": [
40+
"python", "javascript", "typescript", "rust",
41+
"go", "java", "c", "cpp", "csharp"
42+
],
43+
"available_tools": available_tools
44+
}
45+
except Exception as exc:
46+
return {
47+
"status": "degraded",
48+
"error": str(exc)
49+
}

src/server.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env python3
2+
"""
3+
MCP Server for Code Analysis Tools using Anthropic's fastmcp Framework
4+
"""
5+
6+
import importlib
7+
import os
8+
from fastmcp import FastMCP
9+
from starlette.applications import Starlette
10+
from starlette.routing import Mount
11+
import uvicorn
12+
13+
# Create the MCP server instance
14+
mcp = FastMCP("Code Analysis Tools")
15+
16+
# Import and register resources
17+
from src.resources.status import register_status_resource
18+
register_status_resource(mcp)
19+
20+
# Import and register tools
21+
from src.tools import register_all_tools
22+
register_all_tools(mcp)
23+
24+
# Create a Starlette application with the SSE endpoint
25+
app = Starlette(routes=[
26+
# Mount the SSE app at the root
27+
Mount("/", app=mcp.sse_app()),
28+
])
29+
30+
def main():
31+
"""Run the MCP server."""
32+
print("Starting Code Analysis MCP server...")
33+
uvicorn.run(app, host="0.0.0.0", port=8000)
34+
35+
if __name__ == "__main__":
36+
main()

src/tools/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"""Tool registration for the MCP server."""
2+
3+
def register_all_tools(mcp):
4+
"""Register all available tools with the MCP server."""
5+
# Import and register ast-grep tools
6+
from src.tools.ast_grep.tools import register_tools as register_ast_grep_tools
7+
register_ast_grep_tools(mcp)
8+
9+
# In the future, you can add more tool registrations here:
10+
# from src.tools.semgrep.tools import register_tools as register_semgrep_tools
11+
# register_semgrep_tools(mcp)
12+
13+
# from src.tools.pylint.tools import register_tools as register_pylint_tools
14+
# register_pylint_tools(mcp)

src/tools/ast_grep/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"""
2+
MCP Server for ast-grep Tool using Anthropic's fastmcp Framework
3+
"""
4+
5+
__version__ = "0.1.0"
6+
7+
from .server import main
8+
9+
__all__ = ["main"]

0 commit comments

Comments
 (0)