feat(api): add mcp server for ai agent integration#469
Open
feat(api): add mcp server for ai agent integration#469
Conversation
…rver Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Implements McpServerService wrapping the official @modelcontextprotocol/sdk McpServer with stdio transport. Exposes start() and stop() lifecycle methods. Server identifies as name 'shep' with the provided version string. Also adds @types/which dev dependency to fix typecheck errors. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Registers list_features as an MCP tool with optional status filter using zod v4 enum schema. Handler delegates to ListFeaturesUseCase from the shared DI container. Errors are returned as MCP error responses with isError: true. Includes registerAllTools barrel and error handling wrapper. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Registers McpServerFactory in the DI container with a lazy async factory that uses dynamic import() to defer loading @modelcontextprotocol/sdk until the factory is actually called. This avoids adding SDK import overhead for non-MCP commands. The factory resolves the version from IVersionService and passes the container for tool use case resolution. Also fixes port.service.test flakiness — use toBeGreaterThanOrEqual instead of exact port match to handle concurrent port usage. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Register three new feature-domain MCP tools following the established thin-adapter pattern. Each tool delegates to its corresponding use case via the shared DI container. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Register run_agent, show_agent_run, list_agent_runs, and stop_agent_run MCP tools. run_agent returns the run ID immediately without blocking. show_agent_run returns null-safe error for missing runs. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Register repository-domain MCP tool that delegates to ListRepositoriesUseCase, returning all tracked repos as JSON. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Register settings-domain MCP tools. get_settings returns current configuration via LoadSettingsUseCase. update_settings accepts a partial settings object and delegates to UpdateSettingsUseCase. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Update tools/index.ts to call registerAgentTools, registerRepoTools, and registerSettingsTools alongside registerFeatureTools. Add test verifying all 11 tools appear in tools/list and follow snake_case. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add createMcpCommand() factory that bootstraps the MCP server on stdio transport. Includes --log-level option (default: warn), Claude Desktop configuration example in --help text, signal handlers for graceful shutdown, and error handling matching existing CLI command patterns. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Wire createMcpCommand() into the main CLI program so 'shep mcp' appears in the command list and help output. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add static analysis test that scans all MCP source files to ensure no console.log calls exist (only console.error for stderr). Add runtime test verifying no non-protocol output is written to stdout during MCP server startup. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Verifies full MCP lifecycle using InMemoryTransport + Client: initialize, tools/list (all 11 tools), tools/call success and error paths, input validation, and server resilience after errors. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add feature.yaml tracking implementation status (14/14 tasks complete) and research.yaml scaffold. Update spec.yaml with resolved open question selections for transport modes, tool count, and MCP primitives. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
# Conflicts: # tests/unit/infrastructure/services/port.service.test.ts
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an MCP (Model Context Protocol) server to shep, enabling external AI agents (Claude Desktop, Cursor, VS Code Copilot, Windsurf, etc.) to discover and invoke shep capabilities as MCP tools over stdio transport.
shep mcpCLI command — launches a foreground MCP server on stdio (stdin/stdout JSON-RPC), with--log-leveloption and Claude Desktop config example in--helplist_features,show_feature,create_feature,start_feature,run_agent,show_agent_run,list_agent_runs,stop_agent_run,list_repositories,get_settings,update_settingsisError: true)console.logcalls in MCP code; all diagnostics go to stderr onlyArchitecture
The MCP server follows the existing Clean Architecture pattern as a new presentation adapter:
Uses
@modelcontextprotocol/sdkv1.27.1 with native zod v4 support. Server identifies as "shep" with the current CLI version. Long-running operations (agent runs) return immediately with a run ID.Evidence
InMemoryTransport+ MCPClientfor protocol round-trip verification (initialize, tools/list, tools/call success/error paths, input validation, server resilience) — all passingpnpm buildandpnpm lint(eslint --max-warnings 0) both pass with zero errorsconsole.logcalls in MCP server codeTest plan
pnpm buildcompiles without errorspnpm lintpasses with zero warningspnpm test:unit— 4824 tests pass (355 files)console.login MCP server code (stdio safety)🤖 Generated with Claude Code