mcp-server-enhancement

Extend the AI Counsel MCP server with new tools while preserving stdio safety.

Updated Dec 14, 2025
One-click install
npx skills add https://github.com/Raudbjorn/cognitive-construct --skill mcp-server-enhancement-raudbjorn
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: mcp-server-enhancement
Source: https://github.com/Raudbjorn/cognitive-construct/tree/main/rhetoric/scripts/ai-counsel/.claude/skills/mcp-server-enhancement
Command: npx skills add https://github.com/Raudbjorn/cognitive-construct --skill mcp-server-enhancement-raudbjorn

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Extending an MCP server with new tools requires careful adherence to protocol, stdio safety, and robust error handling to prevent system instability and communication corruption. This Skill provides a systematic approach to safely add new tools to the AI Counsel server.

Core Features & Use Cases

  • Pydantic Request/Response Models: Define type-safe models for tool inputs and outputs, ensuring strict validation and clear documentation.
  • Stdio Safety: Learn critical rules to prevent stdout contamination, ensuring the MCP server's communication channel remains intact.
  • Graceful Error Handling: Implement structured error responses for validation failures and runtime exceptions, preventing server crashes.
  • Tool Definition & Routing: Guide for adding new tool definitions to list_tools() and routing calls in call_tool() within server.py.
  • Use Case: You need to expose a new internal API (e.g., a custom data retrieval service) as an MCP tool. This skill guides you through defining its schema, implementing its async handler, and integrating it into the server, allowing AI models to leverage this new capability during deliberations without risking server stability.

Quick Start

Begin by defining Pydantic models for your new tool's request and response in models/schema.py:

In models/schema.py

class NewToolRequest(BaseModel): parameter1: str = Field(..., description="Description of parameter1") class NewToolResponse(BaseModel): status: Literal["success"] result_data: str

Frequently Asked Questions about mcp-server-enhancement

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I safely add new tools to an MCP server without corrupting stdio?

Safely add tools by defining Pydantic models for request/response validation, implementing async handlers that isolate errors, routing calls through call_tool(), and avoiding any stdout writes that contaminate the stdio communication channel. This preserves protocol compliance and server stability.

What's the best way to define input and output schemas for MCP tools?

Use Pydantic BaseModel classes with Field descriptors to define type-safe request and response models. This provides strict validation, clear documentation, and structured error responses when tool inputs fail validation.

How do I handle errors in MCP tool handlers without crashing the server?

Implement graceful error handling in async tool handlers by catching exceptions, returning structured error responses, and logging failures to mcp_server.log. This prevents server crashes and ensures the MCP protocol remains functional.

Can I extend AI Counsel with custom tools that call external APIs?

Yes. Expose internal APIs as MCP tools by defining their schema in Pydantic models, implementing async handlers that call your API, adding tool definitions to list_tools(), and routing calls through call_tool() with comprehensive error isolation.

What steps do I follow to integrate a new tool into server.py?

Define Pydantic request/response models in models/schema.py, add the tool definition to list_tools() with name and description, implement an async handler in call_tool() that validates inputs and returns structured responses, and log all operations to mcp_server.log.

Why is stdio safety critical when extending MCP servers?

MCP servers communicate with AI models over stdio. Any uncontrolled output corrupts the protocol stream and breaks communication. Stdio safety rules prevent accidental logging to stdout and ensure the server remains stable and compliant with the Model Context Protocol.