Skip to content

Commit a7b9344

Browse files
committed
wip local mcp
1 parent ac3a869 commit a7b9344

File tree

5 files changed

+2427
-15
lines changed

5 files changed

+2427
-15
lines changed

.env.example

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,15 @@ OPENROUTER_API_KEY=sk-or-v1-your-key-here
99

1010
# MCP Server Configuration (optional)
1111
# Leave empty to disable MCP integration
12-
# Default Svelte MCP server:
12+
13+
# For HTTP MCP servers (use full URL):
1314
MCP_SERVER_URL=https://mcp.svelte.dev/mcp
1415

15-
# To disable MCP, uncomment the line below:
16+
17+
# For local stdio MCP servers (use command string):
18+
# MCP_SERVER_URL=npx -y @sveltejs/mcp
19+
20+
# To disable MCP, set mcp to empty string
1621
# MCP_SERVER_URL=
1722

1823
# To disable the test component tool, uncomment the line below

AGENTS.md

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,24 +55,46 @@ MODEL=openrouter/meta-llama/llama-3.1-405b-instruct
5555

5656
### MCP Server Configuration
5757

58-
The `MCP_SERVER_URL` environment variable controls MCP (Model Context Protocol) integration:
58+
The `MCP_SERVER_URL` environment variable controls MCP (Model Context Protocol) integration. The tool automatically detects whether to use HTTP or StdIO transport based on the value format.
59+
60+
**HTTP MCP Servers (Remote):**
5961

6062
```bash
6163
# Enable MCP with Svelte server (default for this benchmark)
6264
MCP_SERVER_URL=https://mcp.svelte.dev/mcp
6365

66+
# Use a different HTTP MCP server
67+
MCP_SERVER_URL=https://your-mcp-server.com/mcp
68+
```
69+
70+
**StdIO MCP Servers (Local):**
71+
72+
For local MCP servers, simply provide the command string (any non-HTTP value):
73+
74+
```bash
75+
# Use the default Svelte MCP server via npx
76+
MCP_SERVER_URL=npx -y @sveltejs/mcp
77+
78+
# Use a custom local MCP server
79+
MCP_SERVER_URL=node path/to/your/mcp-server.js
80+
81+
# Use with Bun runtime
82+
MCP_SERVER_URL=bun run src/mcp-server.ts --verbose
83+
```
84+
85+
**Disable MCP:**
86+
87+
```bash
6488
# Disable MCP integration (run without external tools)
6589
MCP_SERVER_URL=
66-
67-
# Use a different MCP server
68-
MCP_SERVER_URL=https://your-mcp-server.com/mcp
6990
```
7091

7192
**Behavior:**
7293

73-
- If `MCP_SERVER_URL` is set and not empty: MCP tools are injected into the agent
94+
- If `MCP_SERVER_URL` starts with `http://` or `https://`: Uses HTTP transport with that URL
95+
- If `MCP_SERVER_URL` is set but not an HTTP URL: Uses StdIO transport, treating the value as a command string
7496
- If `MCP_SERVER_URL` is empty or not set: Agent runs without MCP tools (only built-in tools)
75-
- MCP status is documented in the result JSON and HTML report with a badge
97+
- MCP transport type (HTTP or StdIO) and configuration are documented in the result JSON and HTML report
7698

7799
### Required API Keys
78100

index.ts

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Experimental_Agent as Agent, hasToolCall, stepCountIs } from "ai";
22
import { experimental_createMCPClient as createMCPClient } from "./node_modules/@ai-sdk/mcp/dist/index.mjs";
3+
import { Experimental_StdioMCPTransport as StdioMCPTransport } from "./node_modules/@ai-sdk/mcp/dist/mcp-stdio/index.mjs";
34
import { writeFileSync, mkdirSync, existsSync } from "node:fs";
45
import {
56
generateReport,
@@ -36,6 +37,27 @@ function getTimestampedFilename(prefix: string, extension: string): string {
3637
return `${prefix}-${year}-${month}-${day}-${hours}-${minutes}-${seconds}.${extension}`;
3738
}
3839

40+
/**
41+
* Parse a command string into command and args
42+
* Example: "npx -y @sveltejs/mcp" -> { command: "npx", args: ["-y", "@sveltejs/mcp"] }
43+
*/
44+
function parseCommandString(commandString: string): {
45+
command: string;
46+
args: string[];
47+
} {
48+
const parts = commandString.trim().split(/\s+/);
49+
const command = parts[0] ?? "";
50+
const args = parts.slice(1);
51+
return { command, args };
52+
}
53+
54+
/**
55+
* Check if a string is an HTTP/HTTPS URL
56+
*/
57+
function isHttpUrl(str: string): boolean {
58+
return str.startsWith("http://") || str.startsWith("https://");
59+
}
60+
3961
/**
4062
* Extract ResultWrite content from agent steps
4163
*/
@@ -167,20 +189,29 @@ async function runSingleTest(
167189

168190
// Main execution
169191
async function main() {
170-
// Get MCP server URL from environment (optional)
192+
// Get MCP server URL/command from environment (optional)
171193
const mcpServerUrl = process.env.MCP_SERVER_URL || "";
172194
const mcpEnabled = mcpServerUrl.trim() !== "";
173195

174196
// Check if TestComponent tool is disabled
175197
const testComponentEnabled = process.env.DISABLE_TESTCOMPONENT_TOOL !== "1";
176198

199+
// Determine MCP transport type
200+
const isHttpTransport = mcpEnabled && isHttpUrl(mcpServerUrl);
201+
const mcpTransportType = isHttpTransport ? "HTTP" : "StdIO";
202+
177203
console.log("╔════════════════════════════════════════════════════╗");
178204
console.log("║ SvelteBench 2.0 - Multi-Test ║");
179205
console.log("╚════════════════════════════════════════════════════╝");
180206
console.log(`Model: ${process.env.MODEL}`);
181207
console.log(`MCP Integration: ${mcpEnabled ? "Enabled" : "Disabled"}`);
182208
if (mcpEnabled) {
183-
console.log(`MCP Server URL: ${mcpServerUrl}`);
209+
console.log(`MCP Transport: ${mcpTransportType}`);
210+
if (isHttpTransport) {
211+
console.log(`MCP Server URL: ${mcpServerUrl}`);
212+
} else {
213+
console.log(`MCP StdIO Command: ${mcpServerUrl}`);
214+
}
184215
}
185216
console.log(
186217
`TestComponent Tool: ${testComponentEnabled ? "Enabled" : "Disabled"}`,
@@ -201,15 +232,28 @@ async function main() {
201232
// Set up outputs directory
202233
setupOutputsDirectory();
203234

204-
// Conditionally create MCP client if URL is provided
205-
const mcpClient = mcpEnabled
206-
? await createMCPClient({
235+
// Conditionally create MCP client based on transport type
236+
let mcpClient: Awaited<ReturnType<typeof createMCPClient>> | null = null;
237+
if (mcpEnabled) {
238+
if (isHttpTransport) {
239+
// HTTP transport
240+
mcpClient = await createMCPClient({
207241
transport: {
208242
type: "http",
209243
url: mcpServerUrl,
210244
},
211-
})
212-
: null;
245+
});
246+
} else {
247+
// StdIO transport - treat mcpServerUrl as command string
248+
const { command, args } = parseCommandString(mcpServerUrl);
249+
mcpClient = await createMCPClient({
250+
transport: new StdioMCPTransport({
251+
command,
252+
args,
253+
}),
254+
});
255+
}
256+
}
213257

214258
// Load environment configuration and get model provider
215259
const envConfig = loadEnvConfig();
@@ -286,6 +330,7 @@ async function main() {
286330
metadata: {
287331
mcpEnabled,
288332
mcpServerUrl: mcpEnabled ? mcpServerUrl : null,
333+
mcpTransportType: mcpEnabled ? mcpTransportType : null,
289334
timestamp: new Date().toISOString(),
290335
model: envConfig.modelString,
291336
},

lib/report.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ interface Step {
6969
interface Metadata {
7070
mcpEnabled: boolean;
7171
mcpServerUrl: string | null;
72+
mcpTransportType?: string | null;
7273
timestamp: string;
7374
model: string;
7475
}

0 commit comments

Comments
 (0)