Skip to main content

What is MCP?

MCP (Model Context Protocol) is a protocol developed by Anthropic that lets AI assistants interact with external tools and services. When you expose your service via MCP:
  1. AI can discover your tools: Claude can see all your methods and their parameters
  2. AI can call your tools: Claude can execute methods with proper inputs
  3. AI understands the results: Responses are formatted for AI interpretation
Think of it like giving an AI a “toolbox” - each method in your service becomes a tool the AI can use.

Quick Start

Your service methods are now available as AI tools.

How Methods Become Tools

Each method becomes an MCP tool: Tool names follow the pattern resource.method.

The MCP Protocol

MCP uses JSON-RPC 2.0 as its transport. Here’s how an AI interacts with your server:

Step 1: Initialize

The AI establishes a connection:
Response:

Step 2: Discover Tools

The AI asks what tools are available:
Response:

Step 3: Call a Tool

The AI calls a tool:
Success response:
Error response:

Configuration Options

Customize your MCP server:

Available Options

Complete Example

This example shows a complete MCP service using the recommended package-based organization:

Test with curl

Using with Claude Desktop

Claude Desktop can connect to MCP servers:
  1. Start your server:
  1. Configure Claude Desktop to connect to http://localhost:8080/mcp
  2. Ask Claude:
    • “Create a todo to buy groceries”
    • “Show me all my todos”
    • “Mark the first todo as complete”
Claude will use your MCP tools to fulfill these requests.

Security

Input Validation

Always validate inputs - don’t trust AI-provided data:

Authentication

Add authentication with middleware:

Error Handling

Method Errors

When your method returns an error, MCP wraps it with isError: true:
Response:

Protocol Errors

Invalid requests return JSON-RPC errors:

Multiple Services

Each service needs its own MCP endpoint:

Combining Transports

Use MCP alongside REST and JSON-RPC:
Same business logic, multiple access methods.

Common Questions

How does the AI know what parameters to use?

The tools/list response includes inputSchema for each tool. This JSON Schema tells the AI what parameters are expected, their types, and which are required.

Can I add descriptions to tools?

Tool descriptions come from your method organization. Use clear method names and the WithInstructions option to guide the AI.

What if the AI sends invalid data?

Your method receives the data and should validate it. Return contract.ErrInvalidArgument for validation failures - this shows as an error to the AI.

Can I use MCP and REST together?

Yes, and it’s recommended. REST is great for testing and debugging while MCP serves AI assistants:

What’s Next?