Skip to content

Add MCP server: expose agentlang as Model Context Protocol#658

Open
fractlrao wants to merge 2 commits intomainfrom
add-mcp-server
Open

Add MCP server: expose agentlang as Model Context Protocol#658
fractlrao wants to merge 2 commits intomainfrom
add-mcp-server

Conversation

@fractlrao
Copy link
Copy Markdown
Contributor

Summary

  • Adds an MCP server that mounts on the existing Express app at /mcp (configurable) when mcpServer.enabled is set in app config.
  • Maps every @public event to a module__event tool and every entity to module__Entity__{create,list,get,delete} tools and an agentlang://module/Entity resource.
  • Adds a built-in agentlang_search_tools tool that ranks available tools by query so clients can discover tools without listing them all.
  • Reuses bearer-token auth via verifyAuth and threads the session into tool handlers via AsyncLocalStorage.
  • Stateless transport per request by default (matches SDK guidance); stateful Map<sessionId, transport> mode available via mcpServer.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/mcp with Authorization: Bearer <token>.

Test plan

  • npx vitest run test/runtime/mcpserver-unit.test.ts — 44 unit tests covering schema mapping, tool naming, search scoring, expose toggles
  • npx vitest run test/api/mcpserver.test.ts — 21 integration tests driving the real @modelcontextprotocol/sdk client through tools/list, tools/call (events + entity CRUD), resources/list, resources/read, hot-reload, expose toggles, search, auth gating
  • Full npx vitest run — only the pre-existing llm-service.test.ts fails (requires AGENTLANG_ANTHROPIC_KEY); all other tests pass
  • npx tsc -b tsconfig.src.json — clean
  • npx eslint on changed files — clean
  • prettier --write on changed files — clean

fractlrao added 2 commits May 4, 2026 22:49
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant