tune-mcp
v0.1.6
Published
MCP support for tune
Readme
Tune MCP
MCP (Model Context Protocol) middleware for Tune - connect to MCP servers via stdio, HTTP, or SSE.
Setup for Text Editor
Install in your ~/.tune folder:
cd ~/.tune
npm install tune-mcpAdd to ~/.tune/default.ctx.js:
const tuneMCP = require('tune-mcp')
module.exports = [
...
tuneMCP({
// accepts claude like and vscode like configs
config: "path/to/config.json",
})
// OR single inline mcp config
tuneMCP({
command: "npx",
args: ["-y", "@playwright/mcp@latest"],
mount: "playwright"
})
// OR multiple inline mcp configs
tuneMCP({
playwright: {
command: "npx",
args: ["-y", "@playwright/mcp@latest"],
},
chrome: {
type: "streamable-http",
url: "http://127.0.0.1:12306/mcp"
}
}),
...
]Setup for JavaScript Project
npm install tune-mcp tune-sdkconst tune = require('tune-sdk')
const tuneMCP = require('tune-mcp')
const ctx = tune.makeContext(
tuneMCP({
command: "npx",
args: ["-y", "@playwright/mcp@latest"],
mount: "playwright"
})
)
const result = await ctx.text2run(`
system: @playwright
user: navigate to https://example.com
`)Usage Examples
Per-Chat Connection
system:
connect through stdio
@{| mcp npx -y @playwright/mcp@latest }
@{| mcp stdio npx -y @playwright/mcp@latest }
connect with HTTP streaming
@{| mcp http://localhost:8931/mcp }
@{| mcp streamable-http http://localhost:8931/mcp }
connect with Server-Sent Events
@{| mcp http://localhost:8931/sse }
@{| mcp sse http://localhost:8931/sse }
connect using config file
@{| mcp @path/to/config.json }
@{| mcp config @path/to/config.json }
user:
open https://google.com and make screenshot
assistant:
tool_call: browser_navigate {"url":"https://google.com"}
tool_result:
### Ran Playwright code
```js
await page.goto('https://google.com');
...Configuration Options
Single MCP Server
tuneMCP({
// Command to run MCP server
command: "npx",
args: ["-y", "@playwright/mcp@latest"],
// Mount point prefix for accessing tools
mount: "playwright", // Access tools as @playwright/toolname
// Environment variables for the server
env: {
"API_KEY": "your-api-key"
},
// HTTP/SSE connection
url: "http://localhost:8931/mcp",
type: "streamable-http", // or "sse"
// Headers for HTTP connections
headers: {
"Authorization": "Bearer token"
},
// Expose only specific tools
expose: ["navigate", "click", "type"]
})Multiple MCP Servers
tuneMCP({
"playwright": {
"command": "npx",
"args": ["-y", "@playwright/mcp@latest"],
"env": { "HEADLESS": "true" }
},
"filesystem": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/files"]
},
"api-server": {
"url": "http://localhost:8080/mcp",
"headers": { "Authorization": "Bearer token" }
}
})Config File Format
Create a config file (Claude Desktop format):
{
"mcpServers": {
"playwright": {
"command": "npx",
"args": ["-y", "@playwright/mcp@latest"]
},
"filesystem": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/Users/username/Documents"]
}
}
}Or VS Code format:
{
"mcp": {
"servers": {
"playwright": {
"command": "npx",
"args": ["-y", "@playwright/mcp@latest"]
}
}
}
}Connection Types
stdio (Default)
tuneMCP({
command: "npx",
args: ["-y", "@playwright/mcp@latest"],
mount: "playwright"
})HTTP Streaming
tuneMCP({
url: "http://localhost:8931/mcp",
type: "streamable-http",
mount: "api"
})Server-Sent Events (SSE)
tuneMCP({
url: "http://localhost:8931/sse",
type: "sse",
mount: "events"
})Tool Access Patterns
user: @playwright/navigate # Use specific tool
user: @playwright # connect all available tools
user: @{| mcp stdio some-mcp-server } # Connect dynamically in chatAdvanced Usage
Regex Tool Matching
const tools = await ctx.resolve("playwright/.*", {
match: "regex",
output: "all"
})Filtered Tool Access
tuneMCP({
command: "npx",
args: ["-y", "@modelcontextprotocol/server-everything"],
mount: "everything",
expose: ["echo", "add"] // Only expose specific tools
})Multiple Configurations
const ctx = tune.makeContext(
tuneMCP({ command: "npx", args: ["-y", "server1"], mount: "s1" }),
tuneMCP({ command: "npx", args: ["-y", "server2"], mount: "s2" }),
tuneMCP({ url: "http://api.example.com/mcp", mount: "api" })
)Error Handling
The middleware will throw errors for:
- Missing command or URL configuration
- MCP server connection failures
- Tool execution errors
- Invalid configuration files
try {
const result = await tool.exec({ arg: "value" }, ctx)
} catch (error) {
console.error("MCP tool error:", error.message)
}Environment Variables
In configuration:
tuneMCP({
command: "your-mcp-server",
env: {
"API_KEY": process.env.API_KEY,
"DEBUG": "true"
}
})TODO
- image as tool result
- resources
- auth
