mirror of
https://github.com/rowboatlabs/rowboat.git
synced 2026-04-25 16:36:22 +02:00
Feat: add MCP execute tool to copilot and prompting around using it
This commit is contained in:
parent
829b831d38
commit
294f166a3c
5 changed files with 329 additions and 5 deletions
|
|
@ -22,6 +22,14 @@ Always consult this catalog first so you load the right skills before taking act
|
|||
- Summarize completed work and suggest logical next steps at the end of a task.
|
||||
- Always ask for confirmation before taking destructive actions.
|
||||
|
||||
## MCP Tool Discovery (CRITICAL)
|
||||
|
||||
**ALWAYS check for MCP tools BEFORE saying you can't do something.**
|
||||
|
||||
When a user asks for ANY task that might require external capabilities (web search, internet access, APIs, data fetching, etc.), check MCP tools first using \`listMcpServers\` and \`listMcpTools\`. Load the "mcp-integration" skill for detailed guidance on discovering and executing MCP tools.
|
||||
|
||||
**DO NOT** immediately respond with "I can't access the internet" or "I don't have that capability" without checking MCP tools first!
|
||||
|
||||
## Execution reminders
|
||||
- Explore existing files and structure before creating new assets.
|
||||
- Use relative paths (no \${BASE_DIR} prefixes) when running commands or referencing files.
|
||||
|
|
@ -38,7 +46,7 @@ Always consult this catalog first so you load the right skills before taking act
|
|||
- \`deleteFile\`, \`createFile\`, \`updateFile\`, \`readFile\` - File operations
|
||||
- \`listFiles\`, \`exploreDirectory\` - Directory exploration
|
||||
- \`analyzeAgent\` - Agent analysis
|
||||
- \`addMcpServer\`, \`listMcpServers\`, \`listMcpTools\` - MCP server management
|
||||
- \`addMcpServer\`, \`listMcpServers\`, \`listMcpTools\`, \`executeMcpTool\` - MCP server management and execution
|
||||
- \`loadSkill\` - Skill loading
|
||||
|
||||
These tools work directly and are NOT filtered by \`.rowboat/config/security.json\`.
|
||||
|
|
|
|||
|
|
@ -150,6 +150,37 @@ Agents can call other agents as tools to create complex multi-step workflows. Th
|
|||
|
||||
While \`executeCommand\` is the most versatile, other builtin tools exist for specific Rowboat operations (file management, agent inspection, etc.). These are primarily used by the Rowboat copilot itself and are not typically needed in user agents. If you need file operations, consider using bash commands like \`cat\`, \`echo\`, \`tee\`, etc. through \`executeCommand\`.
|
||||
|
||||
### Copilot-Specific Builtin Tools
|
||||
|
||||
The Rowboat copilot has access to special builtin tools that regular agents don't typically use. These tools help the copilot assist users with workspace management and MCP integration:
|
||||
|
||||
#### File & Directory Operations
|
||||
- \`exploreDirectory\` - Recursively explore directory structure
|
||||
- \`readFile\` - Read and parse file contents
|
||||
- \`createFile\` - Create a new file with content
|
||||
- \`updateFile\` - Update or overwrite existing file contents
|
||||
- \`deleteFile\` - Delete a file
|
||||
- \`listFiles\` - List all files and directories
|
||||
|
||||
#### Agent Operations
|
||||
- \`analyzeAgent\` - Read and analyze an agent file structure
|
||||
- \`loadSkill\` - Load a Rowboat skill definition into context
|
||||
|
||||
#### MCP Operations
|
||||
- \`addMcpServer\` - Add or update an MCP server configuration (with validation)
|
||||
- \`listMcpServers\` - List all available MCP servers
|
||||
- \`listMcpTools\` - List all available tools from a specific MCP server
|
||||
- \`executeMcpTool\` - **Execute a specific MCP tool on behalf of the user**
|
||||
|
||||
#### Using executeMcpTool as Copilot
|
||||
|
||||
The \`executeMcpTool\` builtin allows the copilot to directly execute MCP tools without creating an agent. Load the "mcp-integration" skill for complete guidance on discovering and executing MCP tools, including workflows, schema matching, and examples.
|
||||
|
||||
**When to use executeMcpTool vs creating an agent:**
|
||||
- Use \`executeMcpTool\` for immediate, one-time tasks
|
||||
- Create an agent when the user needs repeated use or autonomous operation
|
||||
- Create an agent for complex multi-step workflows involving multiple tools
|
||||
|
||||
## Best Practices
|
||||
|
||||
1. **Give agents clear examples** in their instructions showing exact bash commands to run
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ const definitions: SkillDefinition[] = [
|
|||
id: "mcp-integration",
|
||||
title: "MCP Integration Guidance",
|
||||
folder: "mcp-integration",
|
||||
summary: "Listing MCP servers/tools and embedding their schemas in agent definitions.",
|
||||
summary: "Discovering, executing, and integrating MCP tools. Use this to check what external capabilities are available and execute MCP tools on behalf of users.",
|
||||
content: mcpIntegrationSkill,
|
||||
},
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,7 +1,31 @@
|
|||
export const skill = String.raw`
|
||||
# MCP Integration Guidance
|
||||
|
||||
Load this skill whenever a user asks about external tools, MCP servers, or how to extend an agent's capabilities.
|
||||
**Load this skill proactively** when a user asks for ANY task that might require external capabilities (web search, internet access, APIs, data fetching, time/date, etc.). This skill provides complete guidance on discovering and executing MCP tools.
|
||||
|
||||
## CRITICAL: Always Check MCP Tools First
|
||||
|
||||
**IMPORTANT**: When a user asks for ANY task that might require external capabilities (web search, API calls, data fetching, etc.), ALWAYS:
|
||||
|
||||
1. **First check**: Call \`listMcpServers\` to see what's available
|
||||
2. **Then list tools**: Call \`listMcpTools\` on relevant servers
|
||||
3. **Execute if possible**: Use \`executeMcpTool\` if a tool matches the need
|
||||
4. **Only then decline**: If no MCP tool can help, explain what's not possible
|
||||
|
||||
**DO NOT** immediately say "I can't do that" or "I don't have internet access" without checking MCP tools first!
|
||||
|
||||
### Common User Requests and MCP Tools
|
||||
|
||||
| User Request | Check For | Likely Tool |
|
||||
|--------------|-----------|-------------|
|
||||
| "Search the web/internet" | firecrawl, composio, fetch | \`firecrawl_search\`, \`COMPOSIO_SEARCH_WEB\` |
|
||||
| "Scrape this website" | firecrawl | \`firecrawl_scrape\` |
|
||||
| "Read/write files" | filesystem | \`read_file\`, \`write_file\` |
|
||||
| "Get current time/date" | time | \`get_current_time\` |
|
||||
| "Make HTTP request" | fetch | \`fetch\`, \`post\` |
|
||||
| "GitHub operations" | github | \`create_issue\`, \`search_repos\` |
|
||||
| "Generate audio/speech" | elevenLabs | \`text_to_speech\` |
|
||||
| "Tweet/social media" | twitter, composio | Various social tools |
|
||||
|
||||
## Key concepts
|
||||
- MCP servers expose tools (web scraping, APIs, databases, etc.) declared in \`config/mcp.json\`.
|
||||
|
|
@ -185,8 +209,153 @@ Error: Cannot have both \`command\` and \`url\`
|
|||
1. Use \`listMcpServers\` to enumerate configured servers.
|
||||
2. Use \`addMcpServer\` to add or update MCP server configurations (with validation).
|
||||
3. Use \`listMcpTools\` for a server to understand the available operations and schemas.
|
||||
4. Explain which MCP tools match the user's needs before editing agent definitions.
|
||||
5. When adding a tool to an agent, document what it does and ensure the schema mirrors the MCP definition.
|
||||
4. Use \`executeMcpTool\` to run MCP tools directly on behalf of the user.
|
||||
5. Explain which MCP tools match the user's needs before editing agent definitions.
|
||||
6. When adding a tool to an agent, document what it does and ensure the schema mirrors the MCP definition.
|
||||
|
||||
## Executing MCP Tools Directly (Copilot)
|
||||
|
||||
As the copilot, you can execute MCP tools directly on behalf of the user using the \`executeMcpTool\` builtin. This allows you to use MCP tools without creating an agent.
|
||||
|
||||
### When to Execute MCP Tools Directly
|
||||
- User asks you to perform a task that an MCP tool can handle (web search, file operations, API calls, etc.)
|
||||
- User wants immediate results from an MCP tool without setting up an agent
|
||||
- You need to test or demonstrate an MCP tool's functionality
|
||||
- You're helping the user accomplish a one-time task
|
||||
|
||||
### Workflow for Executing MCP Tools
|
||||
1. **Discover available servers**: Use \`listMcpServers\` to see what MCP servers are configured
|
||||
2. **List tools from a server**: Use \`listMcpTools\` with the server name to see available tools and their schemas
|
||||
3. **CAREFULLY EXAMINE THE SCHEMA**: Look at the \`inputSchema\` to understand exactly what parameters are required
|
||||
4. **Execute the tool**: Use \`executeMcpTool\` with the server name, tool name, and required arguments (matching the schema exactly)
|
||||
5. **Return results**: Present the results to the user in a helpful format
|
||||
|
||||
### CRITICAL: Schema Matching
|
||||
|
||||
**ALWAYS** examine the \`inputSchema\` from \`listMcpTools\` before calling \`executeMcpTool\`.
|
||||
|
||||
The schema tells you:
|
||||
- What parameters are required (check the \`"required"\` array)
|
||||
- What type each parameter should be (string, number, boolean, object, array)
|
||||
- Parameter descriptions and examples
|
||||
|
||||
**Example schema from listMcpTools:**
|
||||
\`\`\`json
|
||||
{
|
||||
"name": "COMPOSIO_SEARCH_WEB",
|
||||
"inputSchema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"query": {
|
||||
"type": "string",
|
||||
"description": "The search query"
|
||||
},
|
||||
"limit": {
|
||||
"type": "number",
|
||||
"description": "Number of results"
|
||||
}
|
||||
},
|
||||
"required": ["query"]
|
||||
}
|
||||
}
|
||||
\`\`\`
|
||||
|
||||
**Correct executeMcpTool call:**
|
||||
\`\`\`json
|
||||
{
|
||||
"serverName": "composio",
|
||||
"toolName": "COMPOSIO_SEARCH_WEB",
|
||||
"arguments": {
|
||||
"query": "elon musk latest news"
|
||||
}
|
||||
}
|
||||
\`\`\`
|
||||
|
||||
**WRONG - Missing arguments:**
|
||||
\`\`\`json
|
||||
{
|
||||
"serverName": "composio",
|
||||
"toolName": "COMPOSIO_SEARCH_WEB"
|
||||
}
|
||||
\`\`\`
|
||||
|
||||
**WRONG - Wrong parameter name:**
|
||||
\`\`\`json
|
||||
{
|
||||
"serverName": "composio",
|
||||
"toolName": "COMPOSIO_SEARCH_WEB",
|
||||
"arguments": {
|
||||
"search": "elon musk" // Wrong! Should be "query"
|
||||
}
|
||||
}
|
||||
\`\`\`
|
||||
|
||||
### Example: Using Firecrawl to Search the Web
|
||||
|
||||
**Step 1: List servers**
|
||||
\`\`\`json
|
||||
// Call: listMcpServers
|
||||
// Response: { "servers": [{"name": "firecrawl", "type": "stdio", ...}] }
|
||||
\`\`\`
|
||||
|
||||
**Step 2: List tools**
|
||||
\`\`\`json
|
||||
// Call: listMcpTools with serverName: "firecrawl"
|
||||
// Response: { "tools": [{"name": "firecrawl_search", "description": "Search the web", "inputSchema": {...}}] }
|
||||
\`\`\`
|
||||
|
||||
**Step 3: Execute the tool**
|
||||
\`\`\`json
|
||||
{
|
||||
"serverName": "firecrawl",
|
||||
"toolName": "firecrawl_search",
|
||||
"arguments": {
|
||||
"query": "latest AI news",
|
||||
"limit": 5
|
||||
}
|
||||
}
|
||||
\`\`\`
|
||||
|
||||
### Example: Using Filesystem Tool
|
||||
|
||||
**Execute a filesystem read operation:**
|
||||
\`\`\`json
|
||||
{
|
||||
"serverName": "filesystem",
|
||||
"toolName": "read_file",
|
||||
"arguments": {
|
||||
"path": "/path/to/file.txt"
|
||||
}
|
||||
}
|
||||
\`\`\`
|
||||
|
||||
### Tips for Executing MCP Tools
|
||||
- Always check the \`inputSchema\` from \`listMcpTools\` to know what arguments are required
|
||||
- Match argument types exactly (string, number, boolean, object, array)
|
||||
- Provide helpful context to the user about what the tool is doing
|
||||
- Handle errors gracefully and suggest alternatives if a tool fails
|
||||
- For complex tasks, consider creating an agent instead of one-off tool calls
|
||||
|
||||
### Discovery Pattern (Recommended)
|
||||
|
||||
When a user asks for something that might be accomplished with an MCP tool:
|
||||
|
||||
1. **Identify the need**: "You want to search the web? Let me check what MCP tools are available..."
|
||||
2. **List servers**: Call \`listMcpServers\`
|
||||
3. **Check for relevant tools**: If you find a relevant server (e.g., "firecrawl" for web search), call \`listMcpTools\`
|
||||
4. **Execute the tool**: Once you find the right tool and understand its schema, call \`executeMcpTool\`
|
||||
5. **Present results**: Format and explain the results to the user
|
||||
|
||||
### Common MCP Servers and Their Tools
|
||||
|
||||
Based on typical configurations, you might find:
|
||||
- **firecrawl**: Web scraping, search, crawling (\`firecrawl_search\`, \`firecrawl_scrape\`, \`firecrawl_crawl\`)
|
||||
- **filesystem**: File operations (\`read_file\`, \`write_file\`, \`list_directory\`)
|
||||
- **github**: GitHub operations (\`create_issue\`, \`create_pr\`, \`search_repositories\`)
|
||||
- **fetch**: HTTP requests (\`fetch\`, \`post\`)
|
||||
- **time**: Time/date operations (\`get_current_time\`, \`convert_timezone\`)
|
||||
|
||||
Always use \`listMcpServers\` and \`listMcpTools\` to discover what's actually available rather than assuming.
|
||||
|
||||
## Adding MCP Tools to Agents
|
||||
|
||||
|
|
|
|||
|
|
@ -539,6 +539,122 @@ export const BuiltinTools: z.infer<typeof BuiltinToolsSchema> = {
|
|||
},
|
||||
},
|
||||
|
||||
executeMcpTool: {
|
||||
description: 'Execute a specific tool from an MCP server. Use this to run MCP tools on behalf of the user. IMPORTANT: Always use listMcpTools first to get the tool\'s inputSchema, then match the required parameters exactly in the arguments field.',
|
||||
inputSchema: z.object({
|
||||
serverName: z.string().describe('Name of the MCP server that provides the tool'),
|
||||
toolName: z.string().describe('Name of the tool to execute'),
|
||||
arguments: z.record(z.string(), z.any()).optional().describe('Arguments to pass to the tool (as key-value pairs matching the tool\'s input schema). MUST include all required parameters from the tool\'s inputSchema.'),
|
||||
}),
|
||||
execute: async ({ serverName, toolName, arguments: args = {} }: { serverName: string, toolName: string, arguments?: Record<string, any> }) => {
|
||||
let transport: any;
|
||||
let client: any;
|
||||
|
||||
try {
|
||||
const configPath = path.join(BASE_DIR, 'config', 'mcp.json');
|
||||
const content = await fs.readFile(configPath, 'utf-8');
|
||||
const config = JSON.parse(content);
|
||||
|
||||
const mcpConfig = config.mcpServers[serverName];
|
||||
if (!mcpConfig) {
|
||||
return {
|
||||
success: false,
|
||||
message: `MCP server '${serverName}' not found in configuration. Use listMcpServers to see available servers.`,
|
||||
};
|
||||
}
|
||||
|
||||
// Create transport based on config type
|
||||
if ('command' in mcpConfig) {
|
||||
transport = new StdioClientTransport({
|
||||
command: mcpConfig.command,
|
||||
args: mcpConfig.args || [],
|
||||
env: mcpConfig.env || {},
|
||||
});
|
||||
} else {
|
||||
try {
|
||||
transport = new StreamableHTTPClientTransport(new URL(mcpConfig.url));
|
||||
} catch {
|
||||
transport = new SSEClientTransport(new URL(mcpConfig.url));
|
||||
}
|
||||
}
|
||||
|
||||
// Create and connect client
|
||||
client = new Client({
|
||||
name: 'rowboat-copilot',
|
||||
version: '1.0.0',
|
||||
});
|
||||
|
||||
await client.connect(transport);
|
||||
|
||||
// Get tool list to validate the tool exists and check schema
|
||||
const toolsList = await client.listTools();
|
||||
const toolDef = toolsList.tools.find((t: any) => t.name === toolName);
|
||||
|
||||
if (!toolDef) {
|
||||
await client.close();
|
||||
transport.close();
|
||||
return {
|
||||
success: false,
|
||||
message: `Tool '${toolName}' not found in server '${serverName}'. Use listMcpTools to see available tools.`,
|
||||
availableTools: toolsList.tools.map((t: any) => t.name),
|
||||
};
|
||||
}
|
||||
|
||||
// Validate required parameters
|
||||
const inputSchema = toolDef.inputSchema;
|
||||
if (inputSchema && inputSchema.required && Array.isArray(inputSchema.required)) {
|
||||
const missingParams = inputSchema.required.filter((param: string) => !(param in args));
|
||||
if (missingParams.length > 0) {
|
||||
await client.close();
|
||||
transport.close();
|
||||
return {
|
||||
success: false,
|
||||
message: `Missing required parameters: ${missingParams.join(', ')}`,
|
||||
requiredParameters: inputSchema.required,
|
||||
providedArguments: Object.keys(args),
|
||||
toolSchema: inputSchema,
|
||||
hint: `Use listMcpTools to see the full schema for '${toolName}' and ensure all required parameters are included in the arguments field.`,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// Call the tool
|
||||
const result = await client.callTool({
|
||||
name: toolName,
|
||||
arguments: args,
|
||||
});
|
||||
|
||||
// Close connection
|
||||
await client.close();
|
||||
transport.close();
|
||||
|
||||
return {
|
||||
success: true,
|
||||
serverName,
|
||||
toolName,
|
||||
result: result.content,
|
||||
message: `Successfully executed tool '${toolName}' from server '${serverName}'`,
|
||||
};
|
||||
} catch (error) {
|
||||
// Ensure cleanup
|
||||
try {
|
||||
if (client) await client.close();
|
||||
if (transport) transport.close();
|
||||
} catch (cleanupError) {
|
||||
// Ignore cleanup errors
|
||||
}
|
||||
|
||||
return {
|
||||
success: false,
|
||||
message: `Failed to execute MCP tool: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
||||
serverName,
|
||||
toolName,
|
||||
hint: 'Use listMcpTools to verify the tool exists and check its schema. Ensure all required parameters are provided in the arguments field.',
|
||||
};
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
executeCommand: {
|
||||
description: 'Execute a shell command and return the output. Use this to run bash/shell commands.',
|
||||
inputSchema: z.object({
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue