Practical Guide to AI Agent Tool Extension: Built-in Tools, MCP, and Skill Integration

    This article explores how to enhance AI agents by integrating built-in tools, Model Context Protocol (MCP) services, and custom Skills. It covers the runtime loop of tool calling, permission configuration, and best practices for security and troubleshooting to help developers build robust and controlled agentic workflows.

    1. Why AI Agents Need Tools

    Large Language Models (LLMs) excel at understanding and generating language, but they inherently cannot query databases, read or write local files, or execute scripts. A conversational-only model is like a brain without hands. To enable models to actually complete tasks, we must equip them with tools.

    The industry often uses a simplified formula to describe an agent: Agent = LLM + Prompt + Tools. However, this only captures the core elements. Real-world systems also involve context memory, task planning, permission control, and runtime environments, all of which impact agent performance.

    This article uses a generic agent framework to illustrate integration methods. Different frameworks may use varying config file names, field names, and directory structures. Always cross-reference the official documentation of your chosen framework for version requirements and field definitions before integration.

    2. How to Choose Among Three Extension Methods

    Extension Method Problem Solved Typical Scenarios Integration Cost
    Built-in Tools General operations like file, command, task, and network access Code writing, environment configuration, info retrieval Low, out-of-the-box
    Custom Tools or MCP Services Accessing internal systems or external data sources Querying enterprise orders, calling internal APIs Medium, requires connection and auth config
    Skills Solidifying operational workflows for specific tasks Fixed bug triage, code review processes Low to medium, mainly writing description files

    A simple rule of thumb: When you need to “do something,” prioritize built-in or custom tools. When you need to “do something in a fixed way,” write a Skill. When you need to reuse existing data services or want tools to be dynamically discovered, choose MCP.

    3. The Runtime Loop of Tool Calling

    Understanding the runtime loop helps troubleshoot issues. Most frameworks follow a similar execution process:

    1. The framework sends the system prompt, user instructions, and descriptions of available tools to the model.
    2. The model decides whether a tool call is needed. If not, it returns text directly, ending the flow.
    3. If needed, the model outputs a structured tool call, including the tool name and parameters.
    4. The framework checks permissions, executes the tool, and sets a timeout.
    5. The tool’s execution result, including any error messages, is appended to the context and returned to the model.
    6. The model continues reasoning based on the result until the task is complete or the maximum step count is reached.

    Pseudocode:

    1. messages = [system_prompt, user_instruction]
    2. for step in range(MAX_STEPS):
    3. reply = model.chat(messages, tools=tool_schemas, timeout=60)
    4. if not reply.tool_calls:
    5. return reply.text
    6. for call in reply.tool_calls:
    7. if not policy.allow(call):
    8. result = "Permission denied: This operation is not allowed."
    9. else:
    10. try:
    11. result = run_tool(call, timeout=30)
    12. except Exception as e:
    13. result = f"Tool execution failed: {e}"
    14. messages.append(tool_result(call.id, result))
    15. return "Maximum steps reached, task incomplete."

    There are two key points here. First, when a tool fails, return the error message to the model instead of crashing the process, allowing the model to retry using a different approach. Second, timeouts and maximum steps must be set to prevent the model from looping indefinitely and burning through tokens.

    4. Step 1: Configure Permission Boundaries

    Permission configurations dictate what an agent can do. Below is a generic YAML example; field names should be adjusted according to your framework’s actual requirements:

    1. workspace:
    2. root: ./my-project # Agent's working directory
    3. allow_read: true
    4. allow_write: true
    5. deny_paths:
    6. - "~/.ssh"
    7. - "/etc"
    8. commands:
    9. allow:
    10. - "npm test"
    11. - "npm run build"
    12. - "git status"
    13. require_confirm: # Requires user confirmation before execution
    14. - "git push"
    15. - "rm"
    16. network:
    17. allow_domains:
    18. - "api.example.com"

    Configuration principles:

    • Keep the working directory limited to the project scope; do not expose the entire user home directory.
    • Use a whitelist for commands, only enabling low-risk commands like testing, building, and status checks.
    • Place deletion, push, and deployment operations into the confirmation list for per-instance user approval.
    • Only allow necessary domains for network access.

    After configuration, validate with a simple task. For example, ask the agent to create a README file in the working directory, then attempt to read a file outside the directory. The expected result is success for the first step and a permission denial for the second. If both succeed, the permission rules haven’t taken effect; check the configuration file’s loading path.

    5. Step 2: Integrate MCP Services

    MCP (Model Context Protocol) exposes external data sources and tools to agents in a unified manner. Its main differences from regular custom tools are: the server runs independently, the client can dynamically discover tools provided by the service, a single service can be reused by multiple agents, and services are isolated from each other. If you just need to add a simple function to a single project, writing a custom tool directly is more convenient.

    Configuration example for an MCP service started as a local process:

    1. {
    2. "mcpServers": {
    3. "sales-data": {
    4. "command": "node",
    5. "args": ["./mcp/sales-server.js"],
    6. "env": {
    7. "SALES_API_KEY": "${SALES_API_KEY}"
    8. },
    9. "timeout": 30,
    10. "enabled": true
    11. }
    12. }
    13. }

    When integrating remotely, you typically configure the URL and request headers:

    1. {
    2. "mcpServers": {
    3. "sales-remote": {
    4. "url": "https://mcp.example.com/sse",
    5. "headers": {
    6. "Authorization": "Bearer ${SALES_TOKEN}"
    7. },
    8. "timeout": 30,
    9. "enabled": true
    10. }
    11. }
    12. }

    Three things to note here:

    First, do not hardcode keys into config files or code. The ${SALES_API_KEY} above means reading from environment variables, which can be set in the runtime environment before deployment. Also, do not log full request headers.

    Second, the enabled field is used to start and stop the service. Set it to false when not in use to prevent long-term occupation of processes and connections.

    Third, define the timeout explicitly. If it’s too short, normal slow queries will fail; if too long, the model will wait indefinitely. Start with 30 seconds and adjust based on actual response times.

    Validation steps after integration:

    1. Start the agent and check the logs for successful service connection records. If none exist, manually run node ./mcp/sales-server.js and observe the standard error output.
    2. Ask the agent, “What tools can you use?” and confirm the returned list includes sales data-related tools.
    3. Initiate a simple query, like “Check yesterday’s order volume,” and verify the return structure meets expectations.
    4. Intentionally provide an incorrect key to confirm the error message explains the cause, rather than just returning “Failed.”

    6. Step 3: Write Custom Skills

    Tools define what an agent “can do,” while Skills define “how it should do it.” A Skill typically includes a name, applicable scenarios, input parameters, execution steps, output format, and failure fallback. Different frameworks have different conventions for Skill file names and fields; the template below is a generic structure.

    Directory structure example:

    1. skills/
    2. └── bug-triage/
    3. └── SKILL.md

    File content example:

    1. ---
    2. name: bug-triage
    3. description: Locate the root cause based on error stacks or logs, provide a minimal fix, and run validation
    4. when_to_use: Use when the user provides an error stack, failure logs, or a failing test name
    5. inputs:
    6. - error_text: Required, error stack or log snippet
    7. - target_path: Optional, directory of the related code
    8. ---
    9. ## Execution Steps
    10. 1. Parse the error type, file name, and line number.
    11. 2. Use the file reading tool to open the related file, reading only about 50 lines around the error line.
    12. 3. Propose one or two root cause hypotheses and explain the basis for each.
    13. 4. Provide a minimal fix plan and inform the user before modifying files.
    14. 5. Run the corresponding test command for validation.
    15. ## Output Format
    16. - Root cause analysis
    17. - List of modified files
    18. - Validation commands and results
    19. ## Failure Fallback
    20. - If the file is not found, ask the user for the path; do not guess file locations.
    21. - If validation fails, retain current modifications and full output, and report to the user.

    Writing tips:

    • description and when_to_use determine whether the model will trigger the Skill; be specific. Vague descriptions like “help debug code” easily lead to false triggers or no trigger at all.
    • Use numbered lists for steps; each step should do only one thing, making it easier for the model to execute sequentially and for users to verify.
    • Mark whether input parameters are required and provide example values.
    • Failure fallback rules must be specified; otherwise, the model might guess on its own when encountering exceptions, risking misoperations.

    After writing a Skill, test it with three types of inputs: typical questions, boundary cases (e.g., missing file paths), and irrelevant questions (e.g., asking about the weather). Typical questions should trigger the Skill; irrelevant ones should not. If performance is unstable, prioritize revising when_to_use and step descriptions before adjusting the model or parameters.

    7. Design Dimensions for Preset Modes

    Many frameworks support preset modes, packaging a set of strategies into switchable options. Since naming and content vary significantly across frameworks, this article does not treat any specific set of names as a universal standard. When designing presets, you can break them down into four dimensions:

    • Autonomy: The extent to which the model decides operations on its own, determining whether frequent confirmations are needed.
    • Confirmation Frequency: Which operations must be approved by the user, such as file writes, command execution, and network requests.
    • Output Length: Whether the model needs to explain each step. Less explanation means lower token consumption.
    • Tool Scope: The set of tools available in the current mode; smaller is safer.

    For example, a beginner-oriented mode can enable more confirmations and only open read-only tools, while a bulk-task mode for experienced users can reduce confirmations but still require them for deletions and pushes. Refer to your framework’s documentation for specific configuration items.

    8. Troubleshooting Common Issues

    Symptom Possible Cause Troubleshooting Method
    Returns “Permission denied” Path not in allow list, or command unauthorized Check allow and deny_paths rules; verify if path is absolute
    MCP connection failed Wrong startup command, env vars not set, service timeout Manually run service startup command, view standard error output; check env vars
    Tool parameter validation failed Model-generated param type or format mismatch Add types, value ranges, and examples in the tool’s param description
    Skill not triggered description too broad, or overlaps with other Skills Rewrite when_to_use, test trigger conditions with typical questions
    Task repeatedly calls same tool Tool return info unclear, model cannot judge result Make the tool return explicit success/failure status with key data
    Task timeout Single step takes too long or max steps too high Adjust tool timeout and check for circular calls

    When troubleshooting, it is recommended to change only one configuration at a time and record the results of each change. Modifying multiple configs simultaneously makes it difficult to determine which one took effect.

    9. Security and Rollback Recommendations

    An agent’s file writes and command executions directly alter the local environment, requiring additional protective measures:

    • Before starting automated tasks, ensure the working directory is under version control or backed up. This allows quick rollbacks if erroneous modifications occur.
    • Set operations like file deletion, code pushing, service deployment, and permission changes to require user confirmation.
    • Do not log keys, tokens, or personal information. If you need to view request content during debugging, desensitize sensitive fields first.
    • Follow the principle of least privilege. MCP services should only expose necessary tools, networks should only open necessary domains, and commands should only allow whitelisted instructions.
    • For production environments or scenarios involving sensitive data, validate completely in a test environment before opening it up for official tasks.

    10. Conclusion

    Built-in tools, MCP services, and Skills solve problems at different layers. Built-in tools provide general operational capabilities, MCP handles external data and service integration, and Skills solidify fixed working methods. During actual setup, it is recommended to integrate step-by-step in the order of “permissions, tools, MCP, Skills,” validating each step with simple tasks before moving to the next. This keeps the issue scope small and debugging faster.

    As tool protocols and skill descriptions gradually trend towards unification, the cost of sharing capabilities among different agents is expected to decrease. Until then, the most reliable approach is to clearly define the boundaries, permissions, and failure handling for each extension, enabling AI assistants to complete tasks reliably within a controllable scope.