Skip to content

Add MCP server integration for dynamic agent discovery#352

Open
mchawda wants to merge 2 commits intomsitarzewski:mainfrom
mchawda:add-mcp-server-integration
Open

Add MCP server integration for dynamic agent discovery#352
mchawda wants to merge 2 commits intomsitarzewski:mainfrom
mchawda:add-mcp-server-integration

Conversation

@mchawda
Copy link
Copy Markdown

@mchawda mchawda commented Mar 27, 2026

Agent Information

Agent Name: MCP Server Integration
Category: integrations
Specialty: Dynamic agent discovery and composition via Model Context Protocol

Motivation

The Agency has 160+ agents but no programmatic way to discover, search, or compose them at runtime. Every integration today (Cursor rules, Aider conventions, Windsurf rules) requires running shell scripts and copying static files.

This PR adds an MCP server that turns the agent repo into a live, queryable registry — any MCP-compatible client (Cursor, Claude Code, Claude Desktop) can dynamically list, search, and load agent prompts without manual file management.

What's Included

5 Tools:

Tool Description
list_agents Browse all agents, optionally filtered by division
get_agent Load a full agent prompt by slug or name
search_agents Find the right specialist by keyword
compose_team Assemble a recommended team for a project objective
list_divisions See all divisions with agent counts

2 Resources:

URI Description
agency://catalog Full agent catalog as JSON
agency://divisions Division summary with agent counts

Technical Details

  • Built with @modelcontextprotocol/sdk v1.28.0 + Zod for typed params
  • Runs on Bun (also works with Node via tsx)
  • Parses agent frontmatter (gray-matter) + markdown body at startup
  • Auto-detects repo root relative to server location; overridable via AGENCY_AGENTS_PATH
  • Stateless tool calls, structured error responses with isError: true
  • Follows the patterns from the MCP Builder agent in this repo

Testing

  • Parser loads all 161 agents across 13 divisions
  • Search returns relevant results for keyword queries
  • Server initializes and responds to MCP protocol over stdio
  • Tool calls return properly formatted markdown responses

Checklist

  • Follows existing integrations directory structure
  • Includes README with install and configuration instructions
  • No generated/build output committed
  • Uses official MCP SDK patterns
  • Tested with real agent data

Adds a Model Context Protocol server that exposes all Agency agents
as queryable tools and resources. Any MCP client (Cursor, Claude Code,
Claude Desktop) can list, search, compose teams, and load full agent
prompts without manual file copying.

Tools: list_agents, get_agent, search_agents, compose_team, list_divisions
Resources: agency://catalog, agency://divisions
Made-with: Cursor
Adds concrete tool call examples with sample outputs, Node.js/tsx
alternative for users without Bun, and clearer setup instructions.

Made-with: Cursor
@mchawda
Copy link
Copy Markdown
Author

mchawda commented Mar 27, 2026

Per CONTRIBUTING.md guidelines for new tooling/integrations, I've opened #353 as a discussion thread for community feedback on this approach.

Also just pushed an update with:

  • Concrete usage examples with sample tool outputs
  • Node.js/tsx fallback for users without Bun
  • Clearer setup instructions

Happy to iterate based on feedback.

@mhc222
Copy link
Copy Markdown

mhc222 commented Mar 30, 2026

Code Review

1 issue found.


Issue 1 — import.meta.dir is Bun-specific, breaks the documented Node.js + tsx option (score: 100)

In src/index.ts:

const REPO_ROOT =
  process.env.AGENCY_AGENTS_PATH || resolve(import.meta.dir, '../../..');

import.meta.dir is a Bun runtime extension — it does not exist in Node.js. When a user follows the documented Node.js + tsx path and has not set AGENCY_AGENTS_PATH, import.meta.dir evaluates to undefined and node:path's resolve(undefined, '../../..') throws:

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined

The server crashes immediately on startup without a useful error message. The README explicitly documents Node.js v18+ with tsx as a supported alternative runtime, so this is a broken promise for anyone who isn't using Bun.

Fix: replace import.meta.dir with a cross-runtime equivalent:

import { fileURLToPath } from 'node:url';
import { dirname } from 'node:path';

const __dir = typeof import.meta.dir !== 'undefined'
  ? import.meta.dir                                       // Bun
  : dirname(fileURLToPath(import.meta.url));              // Node.js / tsx

const REPO_ROOT = process.env.AGENCY_AGENTS_PATH || resolve(__dir, '../../..');

Reviewed by Code Reviewer agent. Issues are only reported at confidence ≥80/100.

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.

2 participants