Overview
The Model Context Protocol (MCP) is a standardized way for AI models to interact with external tools, resources, and prompts. MCP servers act as intermediaries between AI models and external systems, allowing models to access capabilities beyond their training data.
MythIQ provides a complete platform for creating, deploying, and connecting to MCP servers. This enables you to extend AI models with custom capabilities, such as:
- Accessing real-time data from APIs
- Performing specialized calculations or processing
- Interacting with databases or file systems
- Executing code or commands
- Providing domain-specific knowledge
Extend AI Models with Custom Capabilities
MCP servers allow you to bridge the gap between AI models and external systems, enabling models to perform actions and access information beyond their training data.
Architecture
The MCP architecture consists of several key components:
MCP Server
An MCP server is a service that implements the Model Context Protocol. It defines a set of tools, resources, and prompts that can be used by AI models. Each MCP server has a unique identifier in the format base/slug
.
Deployment
A deployment is a specific version of an MCP server. Each MCP can have multiple deployments, with one being active at a time. A deployment contains the code to execute and the configuration fields for the MCP server.
Connection
A connection is a user-specific configuration for an MCP server. When a user creates a connection to an MCP server, they get a unique URL that can be used to access the server. Connections allow users to customize the behavior of MCP servers for their specific needs.
Communication Protocol
MCP servers use Server-Sent Events (SSE) for communication with clients. This allows for real-time, bidirectional communication between the AI model and the MCP server. The protocol defines standard message formats for requesting tools, resources, and prompts.
Creating MCP Servers
Creating an MCP server involves defining its basic information and implementing the server logic.
Basic Information
Each MCP server requires the following basic information:
- Base: The organization or framework identifier (e.g., "mythiq")
- Slug: A unique identifier for the server (e.g., "weather-api")
- Name: A human-readable name for the server
- Description: A detailed description of what the server does
- Logo: (Optional) A URL to a logo image
- Public: Whether the server is publicly accessible
Server Implementation
The server implementation is written in JavaScript and runs in a Deno environment. This means you can use Deno syntax to import any dependency for your MCP server. The code defines the tools, resources, and prompts that the server provides. Here's a basic template for an MCP server:
// Import dependencies using Deno syntax
import { format } from "https://deno.land/std/datetime/mod.ts";
import { z } from "https://deno.land/x/zod/mod.ts";
// Define metadata for the MCP server
export default {
// Tools that the server provides
tools: [
{
name: "get_weather",
description: "Get the current weather for a location",
input_schema: {
type: "object",
properties: {
location: {
type: "string",
description: "The location to get weather for (city name or coordinates)"
},
units: {
type: "string",
enum: ["metric", "imperial"],
description: "The units to use for temperature (metric or imperial)"
}
},
required: ["location"]
},
output_schema: {
type: "object",
properties: {
temperature: {
type: "number",
description: "The current temperature"
},
conditions: {
type: "string",
description: "The current weather conditions (e.g., sunny, cloudy, rainy)"
}
}
}
}
],
// Resources that the server provides
resources: [
{
name: "weather_data",
description: "Historical weather data for various locations",
uri_patterns: ["weather://*/historical"]
}
],
// Prompts that the server provides
prompts: [
{
name: "weather_forecast",
description: "Generate a weather forecast for a location",
parameters: {
type: "object",
properties: {
location: {
type: "string",
description: "The location to get a forecast for"
},
days: {
type: "integer",
description: "The number of days to forecast"
}
},
required: ["location"]
}
}
]
};
// Handle tool calls
export function handleToolCall(params, context) {
// The tool name is in params.name
if (params.name === "get_weather") {
// Extract arguments
const { location, units = "metric" } = params.arguments;
// Implement the tool logic
// This is just an example - in a real implementation, you would call a weather API
return {
temperature: 22,
conditions: "Sunny"
};
}
// Handle other tools...
// If the tool is not found, throw an error
throw new Error(`Tool ${params.name} not found`);
}
Deploying MCP Servers
Once you've created an MCP server, you can deploy it to make it available for use.
Creating a Deployment
To deploy an MCP server, you need to create a deployment with the server code and configuration. You can do this through the MythIQ API:
curl -X POST https://api.mythiq.ai/v1/mcp \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"base": "mythiq",
"slug": "weather-api",
"name": "Weather API",
"description": "An MCP server for accessing weather data",
"public": true,
"execute": "// Your MCP server code here...",
"fields": [
{
"name": "api_key",
"type": "string",
"description": "API key for the weather service",
"required": true
}
]
}'
Managing Deployments
You can manage your deployments through the MythIQ API:
- List deployments:bash
curl https://api.mythiq.ai/v1/mcp/deployment?mcp=YOUR_MCP_ID \ -H "Authorization: Bearer YOUR_API_KEY"
- Get deployment details:bash
curl https://api.mythiq.ai/v1/mcp/deployment/YOUR_DEPLOYMENT_ID \ -H "Authorization: Bearer YOUR_API_KEY"
- Activate a deployment:bash
curl -X PUT https://api.mythiq.ai/v1/mcp/deployment/YOUR_DEPLOYMENT_ID/status \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_API_KEY" \ -d '{ "active": true }'
Connecting to MCP Servers
To use an MCP server, you need to create a connection to it. This generates a unique URL that you can use to access the server.
Creating a Connection
You can create a connection to an MCP server through the MythIQ API:
curl -X POST https://api.mythiq.ai/v1/mcp/connection \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"mcp": "YOUR_MCP_ID",
"name": "My Weather API Connection",
"config": {
"api_key": "YOUR_WEATHER_API_KEY"
}
}'
The response will include a unique URL for the connection:
{
"result": {
"id": "conn_123abc",
"url": "mcp/abc123",
"name": "My Weather API Connection",
"config": {
"api_key": "YOUR_WEATHER_API_KEY"
},
"mcp": {
"id": "mcp_456def",
"base": "mythiq",
"slug": "weather-api",
"name": "Weather API",
"description": "An MCP server for accessing weather data",
"public": true
}
},
"success": true
}
Using a Connection
To use a connection, you need to connect to the SSE endpoint with the connection URL:
// Connect to the MCP server
const eventSource = new EventSource('https://api.mythiq.ai/mcp/abc123');
// Listen for messages
eventSource.onmessage = (event) => {
const message = JSON.parse(event.data);
console.log('Received message:', message);
// Handle the message based on its type
if (message.type === 'tool_request') {
// Handle tool request
// ...
}
};
// Close the connection when done
eventSource.close();
Tools & Resources
MCP servers can provide three types of capabilities: tools, resources, and prompts.
Tools
Tools are functions that can be called by AI models to perform specific actions. Each tool has:
- Name: A unique identifier for the tool
- Description: A detailed description of what the tool does
- Input Schema: A JSON schema defining the expected input parameters
- Output Schema: A JSON schema defining the expected output format
When an AI model calls a tool, the MCP server executes the corresponding function and returns the result.
Resources
Resources are data sources that can be accessed by AI models. Each resource has:
- Name: A unique identifier for the resource
- Description: A detailed description of what the resource provides
- URI Patterns: Patterns for URIs that can be used to access the resource
AI models can request resources using URIs that match the defined patterns. The MCP server retrieves the requested data and returns it to the model.
Prompts
Prompts are templates for generating text that can be used by AI models. Each prompt has:
- Name: A unique identifier for the prompt
- Description: A detailed description of what the prompt generates
- Parameters: A JSON schema defining the expected parameters for the prompt
AI models can request prompts with specific parameters. The MCP server generates the appropriate text based on the prompt template and returns it to the model.
Examples
Here are some examples of MCP servers for different use cases:
Weather API
An MCP server that provides access to weather data:
// Import dependencies using Deno syntax
import { format } from "https://deno.land/std/datetime/mod.ts";
// Define metadata for the MCP server
export default {
tools: [
{
name: "get_weather",
description: "Get the current weather for a location",
input_schema: {
type: "object",
properties: {
location: {
type: "string",
description: "The location to get weather for"
}
},
required: ["location"]
},
output_schema: {
type: "object",
properties: {
temperature: { type: "number" },
conditions: { type: "string" }
}
}
}
]
};
// Handle tool calls
export function handleToolCall(params, context) {
if (params.name === "get_weather") {
const { location } = params.arguments;
// In a real implementation, you would call a weather API
// using the API key from context.config.api_key
return {
temperature: 22,
conditions: "Sunny"
};
}
}
Database Query
An MCP server that allows querying a database:
// Import dependencies using Deno syntax
import { Client } from "https://deno.land/x/postgres/mod.ts";
// Define metadata for the MCP server
export default {
tools: [
{
name: "query_database",
description: "Query a database for information",
input_schema: {
type: "object",
properties: {
query: {
type: "string",
description: "The SQL query to execute"
}
},
required: ["query"]
},
output_schema: {
type: "array",
items: {
type: "object"
}
}
}
]
};
// Handle tool calls
export function handleToolCall(params, context) {
if (params.name === "query_database") {
const { query } = params.arguments;
// In a real implementation, you would execute the query
// using a database connection with credentials from context.config
return [
{ id: 1, name: "Product A", price: 19.99 },
{ id: 2, name: "Product B", price: 29.99 }
];
}
}