AgentSkillsCN

mcp-management

MCP 工具路由与执行技能。通过节省令牌的隔离机制,实现 MCP 工具的高效路由。借助语义 AI 分类,支持任意 MCP 配置。将工具缓存至 .opencode/mcp-tools.json,以便快速发现工具。

SKILL.md
--- frontmatter
name: mcp-management
description: >-
  MCP tool routing and execution skill. Enables efficient routing of MCP tools
  with token-saving isolation. Uses semantic AI categorization to support ANY
  MCP configuration. Cache at .opencode/mcp-tools.json for fast tool discovery.
compatibility: "OpenCode with any MCP server"
metadata:
  author: Sisyphus
  version: "4.0.0"

MCP Management Skill

Version: 4.0.0 | Architecture: 3-Tier Progressive Disclosure | Categorization: Semantic AI

Overview

This skill enables the mcp-manager agent to efficiently route and execute MCP (Model Context Protocol) tools. By isolating MCP tool definitions in a dedicated subagent context, we reduce main agent token usage by 80-95%.

When to Use This Skill

TriggerCategoryExample
Browser automationbrowser"Take a screenshot", "Click the login button"
GitHub operationsgithub"Get PR #123 details", "List open issues"
GraphQL queriesgraphql"Get the schema", "List available mutations"
Documentation lookupdocs"How do I use useState?", "Find React docs"
Complex reasoningreasoning"Analyze this step by step"

Quick Reference

Tool Categories (AI-Generated)

Categories are generated by /mcp-refresh using semantic AI analysis. Common categories include:

CategoryDescriptionExample Tools
browser-automationWeb interaction, screenshots, DOMclick, screenshot, navigate
version-controlGit, PRs, issues, code reviewget_pull_request, list_issues
documentationLibrary docs, API referencesquery-docs, resolve-library-id
communicationMessaging, notificationspost_message, list_channels
databaseSQL queries, data operationsquery, insert, update

Note: Your actual categories depend on your MCP configuration. Run /mcp-refresh to generate.

Most Common Tools

TaskToolCategory
Screenshottake_screenshotbrowser
Click elementclickbrowser
Fill formfill, fill_formbrowser
Navigatenavigate_pagebrowser
Get page contenttake_snapshotbrowser
Get PR detailsget_pull_requestgithub
List issueslist_issuesgithub
Search codesearch_codegithub
Query docsquery-docsdocs
Step-by-step analysissequentialthinkingreasoning

Routing Decision Tree

code
Task received
│
├─ Contains '__' (exact tool name)?
│  └─ YES → DIRECT PASSTHROUGH: Execute immediately
│
├─ Starts with 'BATCH:'?
│  └─ YES → Parse JSON array, execute sequentially
│
├─ Starts with 'CHAIN:'?
│  └─ YES → Parse chain, execute with variable passing
│
├─ Matches workflow trigger?
│  └─ YES → Check prerequisites, execute if needed
│
├─ Explicit tool name mentioned?
│  └─ YES → Use that tool directly
│
├─ Read .opencode/mcp-tools.json cache
│  └─ Match task keywords against category keywords
│
├─ Multiple categories match?
│  └─ YES → Prefer category with more keyword matches
│
└─ No match?
   └─ Search tool descriptions or ask for clarification

Advanced Features

Direct Passthrough

When you know the exact tool name (contains __), skip routing entirely:

code
Task: "Use MetaMCP_chrome-devtools__take_screenshot"
→ Executes directly without category lookup

Batch Operations

Execute multiple tools in one request using BATCH: prefix:

code
BATCH: [
  {"tool": "take_screenshot", "params": {}},
  {"tool": "get_title", "params": {}}
]
  • Maximum 10 tools per batch
  • Returns array of results in execution order
  • Partial failures reported per-tool

Tool Chaining

Chain tools with output passing using CHAIN: prefix:

code
CHAIN: [
  {"tool": "get_element", "params": {"selector": "#btn"}, "output_as": "el"},
  {"tool": "click", "params": {"element": "$el"}}
]
  • Use $varname to reference previous outputs
  • Maximum 5 tools per chain
  • Chain aborts on first failure

Retry Mechanism

All tool executions automatically retry on failure:

  • Up to 3 attempts
  • Delays: 0s → 1s → 2s
  • Failure report if all attempts fail:
    json
    {"tool": "name", "attempts": 3, "errors": [...], "suggestion": "..."}
    

Workflows

Define prerequisite steps that automatically execute before certain tool operations.

What are Workflows?

Workflows enforce best practices by requiring prerequisite steps before tool execution. For example:

  • Always inspect database structure before running queries
  • Take a page snapshot before clicking elements
  • Review PR details before merging

Quick Start

bash
# Add a workflow from template
/mcp-workflow add --template database

# List active workflows
/mcp-workflow list

# Disable temporarily
/mcp-workflow disable database-safe-query

Built-in Templates

TemplateTriggersPrerequisites
databasequery, select, insertlist_databases → list_tables → inspect_table
browserclick, fill, submittake_snapshot
github-prmerge, reviewget_pr → get_files → get_status

Workflow Modes

ModeBehavior
enforceAuto-run prerequisites (default)
warnShow warning, allow skip
suggestMention only, don't block

Full documentation: workflows.md

Cache Usage

Location: .opencode/mcp-tools.json

If Cache Exists

  1. Read and parse JSON (v2.0.0 schema)
  2. Use categories for keyword-based routing
  3. Use tools map for O(1) tool lookup
  4. Check generated_at - if >24h old, suggest /mcp-refresh

If Cache Missing

  1. Inform user: "Run /mcp-refresh to create tool cache"
  2. Fall back to dynamic tool discovery (slower)

Full cache schema: tool-execution.md

Execution Flow

  1. Parse Intent → Extract keywords from task
  2. Match Category → Find best category match
  3. Select Tool → Choose specific tool within category
  4. Execute → Call tool with mapped parameters
  5. Summarize → Return concise result to main agent

Detailed patterns: tool-execution.md

Result Handling

Summarization Rules

Result TypeAction
Large (>1000 chars)Extract key info only
File operations"File X read/written successfully (N chars)"
Data queries"Found N items. First 3: [...]"
Screenshots"Screenshot saved to /path"
ErrorsInclude error + suggestions

Always Include

  • Success/failure status
  • Key identifiers (IDs, paths, URLs)
  • Count of items (for lists)
  • Actionable next steps
  • Error details (if failed)

Full patterns: result-handling.md

Error Recovery

ErrorRecovery
Tool not foundSuggest similar tools
Execution failedInclude context + retry suggestions
TimeoutReport partial result + suggestions
Cache missingPrompt /mcp-refresh

Full recovery procedures: error-handling.md

Example Invocations

Browser: Take Screenshot

code
Task: "Take a screenshot of the current page"
Tool: MetaMCP_chrome-devtools__take_screenshot
Result: "Screenshot saved to ./screenshot.png"

GitHub: Get PR

code
Task: "Get details of PR #123 in owner/repo"
Tool: MetaMCP_github-zengaming__get_pull_request
Params: { owner: "owner", repo: "repo", pull_number: 123 }
Result: "PR #123: 'Fix bug' by @user, open, +50/-20, 3 files"

Docs: Query Library

code
Task: "How do I use useState in React?"
1. MetaMCP_context7__resolve-library-id → "/facebook/react"
2. MetaMCP_context7__query-docs → Usage examples
Result: "useState returns [state, setState]. Example: ..."

Reference Documentation

DocumentContentWhen to Read
tool-categories.mdFull tool lists per categoryNeed specific tool
tool-execution.mdRouting algorithm, cache schemaComplex routing
result-handling.mdSummarization patternsLarge results
error-handling.mdRecovery proceduresErrors occur

Best Practices

  1. Prefer Cached Routing - Always check cache first
  2. Batch Operations - Execute related operations in sequence
  3. Summarize Aggressively - Main agent needs actions, not data
  4. Fail Fast - Ask for clarification rather than guessing
  5. Include Context - Errors should be actionable