Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Guidance for integrating MCP (Model Context Protocol) servers into Claude Code plugins.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/tool-usage.md
1# Using MCP Tools in Commands and Agents23Complete guide to using MCP tools effectively in Claude Code plugin commands and agents.45## Overview67Once an MCP server is configured, its tools become available with the prefix `mcp__plugin_<plugin-name>_<server-name>__<tool-name>`. Use these tools in commands and agents just like built-in Claude Code tools.89## Tool Naming Convention1011### Format1213```14mcp__plugin_<plugin-name>_<server-name>__<tool-name>15```1617### Examples1819**Asana plugin with asana server:**20- `mcp__plugin_asana_asana__asana_create_task`21- `mcp__plugin_asana_asana__asana_search_tasks`22- `mcp__plugin_asana_asana__asana_get_project`2324**Custom plugin with database server:**25- `mcp__plugin_myplug_database__query`26- `mcp__plugin_myplug_database__execute`27- `mcp__plugin_myplug_database__list_tables`2829### Discovering Tool Names3031**Use `/mcp` command:**32```bash33/mcp34```3536This shows:37- All available MCP servers38- Tools provided by each server39- Tool schemas and descriptions40- Full tool names for use in configuration4142## Using Tools in Commands4344### Pre-Allowing Tools4546Specify MCP tools in command frontmatter:4748```markdown49---50description: Create a new Asana task51allowed-tools: [52"mcp__plugin_asana_asana__asana_create_task"53]54---5556# Create Task Command5758To create a task:591. Gather task details from user602. Use mcp__plugin_asana_asana__asana_create_task with the details613. Confirm creation to user62```6364### Multiple Tools6566```markdown67---68allowed-tools: [69"mcp__plugin_asana_asana__asana_create_task",70"mcp__plugin_asana_asana__asana_search_tasks",71"mcp__plugin_asana_asana__asana_get_project"72]73---74```7576### Wildcard (Use Sparingly)7778```markdown79---80allowed-tools: ["mcp__plugin_asana_asana__*"]81---82```8384**Caution:** Only use wildcards if the command truly needs access to all tools from a server.8586### Tool Usage in Command Instructions8788**Example command:**89```markdown90---91description: Search and create Asana tasks92allowed-tools: [93"mcp__plugin_asana_asana__asana_search_tasks",94"mcp__plugin_asana_asana__asana_create_task"95]96---9798# Asana Task Management99100## Searching Tasks101102To search for tasks:1031. Use mcp__plugin_asana_asana__asana_search_tasks1042. Provide search filters (assignee, project, etc.)1053. Display results to user106107## Creating Tasks108109To create a task:1101. Gather task details:111- Title (required)112- Description113- Project114- Assignee115- Due date1162. Use mcp__plugin_asana_asana__asana_create_task1173. Show confirmation with task link118```119120## Using Tools in Agents121122### Agent Configuration123124Agents can use MCP tools autonomously without pre-allowing them:125126```markdown127---128name: asana-status-updater129description: This agent should be used when the user asks to "update Asana status", "generate project report", or "sync Asana tasks"130model: inherit131color: blue132---133134## Role135136Autonomous agent for generating Asana project status reports.137138## Process1391401. **Query tasks**: Use mcp__plugin_asana_asana__asana_search_tasks to get all tasks1412. **Analyze progress**: Calculate completion rates and identify blockers1423. **Generate report**: Create formatted status update1434. **Update Asana**: Use mcp__plugin_asana_asana__asana_create_comment to post report144145## Available Tools146147The agent has access to all Asana MCP tools without pre-approval.148```149150### Agent Tool Access151152Agents have broader tool access than commands:153- Can use any tool Claude determines is necessary154- Don't need pre-allowed lists155- Should document which tools they typically use156157## Tool Call Patterns158159### Pattern 1: Simple Tool Call160161Single tool call with validation:162163```markdown164Steps:1651. Validate user provided required fields1662. Call mcp__plugin_api_server__create_item with validated data1673. Check for errors1684. Display confirmation169```170171### Pattern 2: Sequential Tools172173Chain multiple tool calls:174175```markdown176Steps:1771. Search for existing items: mcp__plugin_api_server__search1782. If not found, create new: mcp__plugin_api_server__create1793. Add metadata: mcp__plugin_api_server__update_metadata1804. Return final item ID181```182183### Pattern 3: Batch Operations184185Multiple calls with same tool:186187```markdown188Steps:1891. Get list of items to process1902. For each item:191- Call mcp__plugin_api_server__update_item192- Track success/failure1933. Report results summary194```195196### Pattern 4: Error Handling197198Graceful error handling:199200```markdown201Steps:2021. Try to call mcp__plugin_api_server__get_data2032. If error (rate limit, network, etc.):204- Wait and retry (max 3 attempts)205- If still failing, inform user206- Suggest checking configuration2073. On success, process data208```209210## Tool Parameters211212### Understanding Tool Schemas213214Each MCP tool has a schema defining its parameters. View with `/mcp`.215216**Example schema:**217```json218{219"name": "asana_create_task",220"description": "Create a new Asana task",221"inputSchema": {222"type": "object",223"properties": {224"name": {225"type": "string",226"description": "Task title"227},228"notes": {229"type": "string",230"description": "Task description"231},232"workspace": {233"type": "string",234"description": "Workspace GID"235}236},237"required": ["name", "workspace"]238}239}240```241242### Calling Tools with Parameters243244Claude automatically structures tool calls based on schema:245246```typescript247// Claude generates this internally248{249toolName: "mcp__plugin_asana_asana__asana_create_task",250input: {251name: "Review PR #123",252notes: "Code review for new feature",253workspace: "12345",254assignee: "67890",255due_on: "2025-01-15"256}257}258```259260### Parameter Validation261262**In commands, validate before calling:**263264```markdown265Steps:2661. Check required parameters:267- Title is not empty268- Workspace ID is provided269- Due date is valid format (YYYY-MM-DD)2702. If validation fails, ask user to provide missing data2713. If validation passes, call MCP tool2724. Handle tool errors gracefully273```274275## Response Handling276277### Success Responses278279```markdown280Steps:2811. Call MCP tool2822. On success:283- Extract relevant data from response284- Format for user display285- Provide confirmation message286- Include relevant links or IDs287```288289### Error Responses290291```markdown292Steps:2931. Call MCP tool2942. On error:295- Check error type (auth, rate limit, validation, etc.)296- Provide helpful error message297- Suggest remediation steps298- Don't expose internal error details to user299```300301### Partial Success302303```markdown304Steps:3051. Batch operation with multiple MCP calls3062. Track successes and failures separately3073. Report summary:308- "Successfully processed 8 of 10 items"309- "Failed items: [item1, item2] due to [reason]"310- Suggest retry or manual intervention311```312313## Performance Optimization314315### Batching Requests316317**Good: Single query with filters**318```markdown319Steps:3201. Call mcp__plugin_api_server__search with filters:321- project_id: "123"322- status: "active"323- limit: 1003242. Process all results325```326327**Avoid: Many individual queries**328```markdown329Steps:3301. For each item ID:331- Call mcp__plugin_api_server__get_item332- Process item333```334335### Caching Results336337```markdown338Steps:3391. Call expensive MCP operation: mcp__plugin_api_server__analyze3402. Store results in variable for reuse3413. Use cached results for subsequent operations3424. Only re-fetch if data changes343```344345### Parallel Tool Calls346347When tools don't depend on each other, call in parallel:348349```markdown350Steps:3511. Make parallel calls (Claude handles this automatically):352- mcp__plugin_api_server__get_project353- mcp__plugin_api_server__get_users354- mcp__plugin_api_server__get_tags3552. Wait for all to complete3563. Combine results357```358359## Integration Best Practices360361### User Experience362363**Provide feedback:**364```markdown365Steps:3661. Inform user: "Searching Asana tasks..."3672. Call mcp__plugin_asana_asana__asana_search_tasks3683. Show progress: "Found 15 tasks, analyzing..."3694. Present results370```371372**Handle long operations:**373```markdown374Steps:3751. Warn user: "This may take a minute..."3762. Break into smaller steps with updates3773. Show incremental progress3784. Final summary when complete379```380381### Error Messages382383**Good error messages:**384```385❌ "Could not create task. Please check:3861. You're logged into Asana3872. You have access to workspace 'Engineering'3883. The project 'Q1 Goals' exists"389```390391**Poor error messages:**392```393❌ "Error: MCP tool returned 403"394```395396### Documentation397398**Document MCP tool usage in command:**399```markdown400## MCP Tools Used401402This command uses the following Asana MCP tools:403- **asana_search_tasks**: Search for tasks matching criteria404- **asana_create_task**: Create new task with details405- **asana_update_task**: Update existing task properties406407Ensure you're authenticated to Asana before running this command.408```409410## Testing Tool Usage411412### Local Testing4134141. **Configure MCP server** in `.mcp.json`4152. **Install plugin locally** in `.claude-plugin/`4163. **Verify tools available** with `/mcp`4174. **Test command** that uses tools4185. **Check debug output**: `claude --debug`419420### Test Scenarios421422**Test successful calls:**423```markdown424Steps:4251. Create test data in external service4262. Run command that queries this data4273. Verify correct results returned428```429430**Test error cases:**431```markdown432Steps:4331. Test with missing authentication4342. Test with invalid parameters4353. Test with non-existent resources4364. Verify graceful error handling437```438439**Test edge cases:**440```markdown441Steps:4421. Test with empty results4432. Test with maximum results4443. Test with special characters4454. Test with concurrent access446```447448## Common Patterns449450### Pattern: CRUD Operations451452```markdown453---454allowed-tools: [455"mcp__plugin_api_server__create_item",456"mcp__plugin_api_server__read_item",457"mcp__plugin_api_server__update_item",458"mcp__plugin_api_server__delete_item"459]460---461462# Item Management463464## Create465Use create_item with required fields...466467## Read468Use read_item with item ID...469470## Update471Use update_item with item ID and changes...472473## Delete474Use delete_item with item ID (ask for confirmation first)...475```476477### Pattern: Search and Process478479```markdown480Steps:4811. **Search**: mcp__plugin_api_server__search with filters4822. **Filter**: Apply additional local filtering if needed4833. **Transform**: Process each result4844. **Present**: Format and display to user485```486487### Pattern: Multi-Step Workflow488489```markdown490Steps:4911. **Setup**: Gather all required information4922. **Validate**: Check data completeness4933. **Execute**: Chain of MCP tool calls:494- Create parent resource495- Create child resources496- Link resources together497- Add metadata4984. **Verify**: Confirm all steps succeeded4995. **Report**: Provide summary to user500```501502## Troubleshooting503504### Tools Not Available505506**Check:**507- MCP server configured correctly508- Server connected (check `/mcp`)509- Tool names match exactly (case-sensitive)510- Restart Claude Code after config changes511512### Tool Calls Failing513514**Check:**515- Authentication is valid516- Parameters match tool schema517- Required parameters provided518- Check `claude --debug` logs519520### Performance Issues521522**Check:**523- Batching queries instead of individual calls524- Caching results when appropriate525- Not making unnecessary tool calls526- Parallel calls when possible527528## Conclusion529530Effective MCP tool usage requires:5311. **Understanding tool schemas** via `/mcp`5322. **Pre-allowing tools** in commands appropriately5333. **Handling errors gracefully**5344. **Optimizing performance** with batching and caching5355. **Providing good UX** with feedback and clear errors5366. **Testing thoroughly** before deployment537538Follow these patterns for robust MCP tool integration in your plugin commands and agents.539