feature/mcp-feature #10
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "feature/mcp-feature"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Runfeat: add MCP server mode for direct integration with AI coding agents
Motivation
This PR introduces MCP (Model Context Protocol) server mode to Grokkit, enabling seamless integration with MCP-compatible AI coding agents like Claude Code, Cursor, or similar tools. By running Grokkit as an MCP server (
grokkit mcp), external agents can directly call Grokkit's core functionalities (e.g., linting, analysis, documentation generation) as tools or access resources like recipes and prompts. This enhances Grokkit's utility in AI-assisted workflows without requiring manual CLI invocations.The feature is configurable via
config.toml(e.g., enabling/disabling tools/resources) and uses stdio transport for compatibility with common clients. It builds on existing commands by extracting reusable logic into modular packages, improving code organization and testability.Key benefits:
This addresses feature request #42 (AI agent integration) and prepares for future expansions like more tools/resources.
Changes
grokkit mcpto start the MCP server over stdio (blocks until client disconnects). Configurable via[mcp]section inconfig.toml(defaults: enabled, all tools/resources).internal/mcp/server.gousinggithub.com/mark3labs/mcp-goSDK. Registers 6 tools (lint_code,analyze_code,generate_docs,generate_tests,generate_commit_msg,run_recipe) and 3 resources (recipes://local,recipes://global,prompts://language).internal/analyze(exportedDiscoverSourceFiles,BuildProjectContext).internal/docs(exportedBuildDocsMessages).internal/testgenfor test generation prompts.internal/recipe/list.goandinternal/prompts/list.gofor resource listing.go.mod/go.sumto includemark3labs/mcp-goand related packages (e.g.,google/uuid,yosida95/uritemplate).docs/user-guide/mcp.mdwith usage examples, config details, and integration notes. UpdatedREADME.mdwith a brief mention and link.config/config.go(e.g.,mcp.enabled = true, default tools/resources lists).cmd/analyze_test.go,cmd/docs_test.go) to use exported functions. Added new unit tests for MCP handlers (internal/mcp/server_test.go), modular components (e.g.,internal/analyze/analyze_test.go,internal/docs/docs_test.go,internal/testgen/testgen_test.go).No breaking changes; existing CLI commands remain unaffected.
Testing Notes
TestDiscoverSourceFiles,TestBuildDocsMessages,TestGetTestPrompt).go test ./...(coverage ~85% for new code).TestHandleLintCodeverifies output without real files/linters).grokkit mcp(ensure MCP is enabled in config). Use a tool like Claude Code to call tools (e.g., "Use grokkit to lint main.go and generate docs").lint_codeon a valid file should return lint results;analyze_codeshould generate a Markdown report.recipes://localto list recipes; verify JSON output.generate_docs) return graceful errors; empty dirs return appropriate messages.config.toml(e.g.,tools = ["lint_code"]) and verify it's unavailable.StreamSilent).If issues arise, check logs for MCP errors (e.g., invalid tool calls). Feedback welcome on tool/resource expansions!