Back to Agent Skills

MCP Server Creation

Design and build MCP servers that expose custom tools, resources, and prompts for AI agents using the Model Context Protocol.

When to Use

  • -You want to give your AI agent a custom capability
  • -You need to integrate existing APIs or databases as agent-accessible tools
  • -You are building an agent system that needs pluggable tool support
  • -You want to package reusable capabilities as MCP servers

Inputs

Tool/resource specifications, programming language (Python/TS), transport config.

Outputs

MCP server code, tool definitions, deployment guide, example client usage.

Tools Required

MCP SDK (TS/Python)MCP InspectorOpenAI/Claude

Skill Safety

Every 4M Labs skill is designed to be readable, auditable, and easy to modify before use. Treat skills like code: review them before running, check tool permissions, and keep secrets out of prompts.

SKILL.md

---
name: mcp-server-creation
description: Gives an agent the ability to design, build, test, and document MCP servers that expose tools, resources, and prompts for AI agents using the Model Context Protocol.
inputs:
  - tool_specs: List of tools with name, description, input schema, output schema
  - resource_specs: Optional resources (URIs, handlers, subscription support)
  - transport_config: stdio, SSE, or Streamable HTTP transport configuration
  - language: TypeScript or Python (MCP SDK)
outputs:
  - mcp_server_source: Complete, runnable MCP server code
  - tool_definitions: JSON schema for each tool
  - client_example: How to connect and use from a client
  - deployment_guide: stdio config for Claude/OpenCode, or Docker for remote
tools:
  - typescript_sdk: "@modelcontextprotocol/sdk" for TypeScript servers
  - python_sdk: mcp package for Python servers
  - mcp_inspector: Test and debug MCP server tools
  - openai_api: Reference for tool-use format compatibility
safety:
  - Validate all tool input schemas with JSON Schema
  - Never expose filesystem, shell, or database tools without authentication
  - Follow MCP security best practices
  - Set reasonable rate limits on tool execution
  - Log all tool invocations for audit
---

# MCP Server Creation Skill

Design, build, test, and document MCP servers that expose custom tools, resources, and prompts for AI agents using the Model Context Protocol.

## When to Use

- You want to give your AI agent a custom capability (search a database, call an API, read a file)
- You need to integrate existing APIs or databases as agent-accessible tools
- You are building an agent system that needs pluggable tool support
- You want to package reusable capabilities as MCP servers for your team

## How It Works

1. **Plan**: Define what tools/resources the server exposes. Sketch input/output schemas.
2. **Implement**: Use MCP SDK (TypeScript or Python) to create server with tool handlers.
3. **Test**: Run locally with MCP Inspector. Verify tool calls, error handling, edge cases.
4. **Document**: Write usage examples, input schemas, and deployment instructions.
5. **Deploy**: Configure for stdio (direct agent integration) or remote (SSE/HTTP).

## Server Patterns

- **stdio**: Simplest. Run as subprocess of the agent. Best for local tools.
- **SSE**: Remote server with Server-Sent Events. Good for shared tools.
- **Streamable HTTP**: Stateless HTTP transport. Best for production deployments.

## Example Prompt

"Create an MCP server in TypeScript that exposes two tools: 1) search_docs(query: string) that searches a PostgreSQL database of documentation using pgvector similarity search, and 2) get_doc(id: string) that returns the full document content. Use stdio transport. Include error handling and input validation."

## Related

- Recipe: /recipes/internal-ai-os
- Skill: /skills/rag-document-ingestion
Download SKILL.md

Related Recipes

Want mcp server creation running in your business?

4M Labs can deploy mcp server creation as a production workflow:

  • Connected to your tools and data sources
  • Secured for your team with proper access controls
  • Deployed with monitoring and error handling
  • Documented for handoff and future maintenance
Book an Implementation Sprint