Add MCP server: expose agentlang as Model Context Protocol#658
Open
Add MCP server: expose agentlang as Model Context Protocol#658
Conversation
…resources Mounts a Streamable HTTP MCP server on the existing Express app at a configurable path (default /mcp) when mcpServer.enabled is set. Maps every @public event to a `module__event` tool, every entity to `module__Entity__{create,list,get,delete}` tools, and every entity to an `agentlang://module/Entity` resource. Tool listing re-walks the module registry per request, so dynamically interned modules show up without a restart. Bearer-token auth on /mcp reuses verifyAuth so RBAC is threaded into tool handlers via AsyncLocalStorage. Stateless transport per request (matches the SDK's recommended pattern); a stateful Map<sessionId, transport> mode is available via mcpServer.stateless: false. Adds a built-in `agentlang_search_tools` tool that ranks tools by query terms across name, module, and description so clients can discover tools without enumerating the full list. Tests: 44 unit tests covering schema mapping, tool naming, search scoring, and expose toggles; 21 integration tests driving the real @modelcontextprotocol/sdk client through tools/list, tools/call, resources/list, resources/read, hot-reload, expose toggles, search, and auth gating.
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
/mcp(configurable) whenmcpServer.enabledis set in app config.@publicevent to amodule__eventtool and every entity tomodule__Entity__{create,list,get,delete}tools and anagentlang://module/Entityresource.agentlang_search_toolstool that ranks available tools by query so clients can discover tools without listing them all.verifyAuthand threads the session into tool handlers viaAsyncLocalStorage.Map<sessionId, transport>mode available viamcpServer.stateless: false.Config
{ "service": { "port": 8080 }, "auth": { "enabled": true }, "mcpServer": { "enabled": true, "path": "/mcp", "expose": { "events": true, "entities": true, "resources": true } } }Point an MCP client (Claude Desktop, Cursor, etc.) at
http://<host>:8080/mcpwithAuthorization: Bearer <token>.Test plan
npx vitest run test/runtime/mcpserver-unit.test.ts— 44 unit tests covering schema mapping, tool naming, search scoring, expose togglesnpx vitest run test/api/mcpserver.test.ts— 21 integration tests driving the real@modelcontextprotocol/sdkclient through tools/list, tools/call (events + entity CRUD), resources/list, resources/read, hot-reload, expose toggles, search, auth gatingnpx vitest run— only the pre-existingllm-service.test.tsfails (requiresAGENTLANG_ANTHROPIC_KEY); all other tests passnpx tsc -b tsconfig.src.json— cleannpx eslinton changed files — cleanprettier --writeon changed files — clean