MCP server for semantic agent selection using pgvector embeddings
npm install tarvacode-agent-selectorAn MCP (Model Context Protocol) server for semantic agent selection using pgvector embeddings in Supabase.
This server provides tools to find the best specialized Claude Code agent for a given task using semantic similarity matching:
1. select_best_agent - Find the optimal agent for a task description
2. list_agents - List all available agents
3. get_agent_skills - Get skills for a specific agent
```
Task Description
↓
OpenAI Embedding (text-embedding-3-small)
↓
Supabase Stored Procedure (two-tier selection)
- Top-K agent shortlist by embedding similarity
- Rerank by max skill similarity
- Fallback to chief-technology-architect
↓
Agent Name
- Node.js >= 18.0.0
- npm or yarn
- Access to:
- Supabase project with pgvector extension
- OpenAI API key
`bash`
cd find-best-agent/mcp-server
npm install
npm run build
| Variable | Description | Required |
|----------|-------------|----------|
| OPENAI_API_KEY | OpenAI API key for embeddings | Yes |SUPABASE_URL
| | Supabase project URL | Yes |SUPABASE_ANON_KEY
| | Supabase anon/public key | Yes |
Add to your project's .claude/mcp.json:
`json`
{
"mcpServers": {
"tarvacode-agent-selector": {
"command": "node",
"args": ["./find-best-agent/mcp-server/dist/index.js"],
"env": {
"OPENAI_API_KEY": "${OPENAI_API_KEY}",
"SUPABASE_URL": "${SUPABASE_URL}",
"SUPABASE_ANON_KEY": "${SUPABASE_ANON_KEY}"
}
}
}
}
Finds the best agent for a task using two-tier semantic matching.
Input:
`json`
{
"task": "Design a PostgreSQL schema for a multi-tenant SaaS application",
"match_threshold": 0.5
}
Output:
`json`
{
"agent_name": "database-architect"
}
Lists all available agents.
Output:
`json`
{
"agents": [
{
"name": "database-architect",
"description": "World-class Database Architect...",
"tools": ["Read", "Write", "Edit", "Grep", "Glob", "Bash", "Task"]
}
],
"count": 20
}
Gets skills for a specific agent.
Input:
`json`
{
"agent_name": "database-architect"
}
Output:
`json`
{
"agent_name": "database-architect",
"skills": [
{
"skill_id": "A1",
"skill_name": "Workload Classification",
"domain": "A: Architecture strategy",
"deliverable": "classification_report"
}
],
"count": 52
}
`bashRun in development mode
npm run dev
The stored procedure implements a two-tier selection:
1. Agent-Level Shortlist: Find top-K agents by cosine similarity between task embedding and agent embeddings
2. Skill-Level Rerank: For each candidate, compute max similarity against skill embeddings
3. Final Score: Use the higher of agent similarity or max skill similarity
4. Threshold: Only return agents above the match threshold
5. Fallback: Return "chief-technology-architect" if no match above threshold
This approach balances speed (coarse agent matching) with accuracy (granular skill validation).