Skip to main content

Model Context Protocol (MCP)

Create a customized Squid MCP Server to help define tools and actions for your AI agents.

What is MCP?

MCP (Model Context Protocol) is an open protocol to facilitate communication between AI agents and external services. It allows Squid AI agents to access tools and perform actions by connecting to an MCP server, which exposes various functionalities through defined tools.

Squid's MCP Functionality

Squid provides built-in support for creating and managing MCP servers, making it easy to define tools and actions that AI agents can utilize.

The @mcpServer Decorator

To create an MCP Server, simply add the @mcpServer decorator to a service that extends the SquidService base class in your backend project:

import {mcpServer, SquidService} from "@squidcloud/backend";

@mcpServer({
name: 'myMcp',
id: 'myMcp',
description: 'This MCP knows how to provide data about the weather',
version: '1.0.0',
})
export class McpService extends SquidService {
...
}

Adding tools using @mcpTool

Next, add tools to your server using the @mcpTool decorator. Each tool can have its own input schema and custom functionality:

import {mcpServer, mcpTool, SquidService} from "@squidcloud/backend";

@mcpServer({
name: 'myMcp',
id: 'myMcp',
description: 'This MCP knows how to provide data about the weather',
version: '1.0.0',
})
export class McpService extends SquidService {

@mcpTool({
description: 'This tool returns the current weather for a given city',
inputSchema: {
type: 'object',
properties: {
city: {
type: 'string',
description: 'The name of the city to get the weather for',
},
},
required: ['city'],
},

})
async getWeather({city} ) {
// Insert custom logic here,
// For example, call a weather API endpoint to get real data
return `The current weather in ${city} is sunny with a temperature of 25°C.`;
}
}

Each tool is exposed via the MCP server and will be invoked by connected AI agents based on the tool's description.

Secure your MCP with @mcpAuthorizer

To ensure that only authorized AI agents can access your MCP server, implement the @mcpAuthorizer decorator. This method will handle authorization requests and determine if the incoming request is valid.

import { mcpAuthorizer, McpAuthorizationRequest, mcpTool, mcpServer, SquidService } from '@squidcloud/backend';

@mcpServer({
name: 'myMcp',
id: 'myMcp',
description: 'This MCP knows how to provide data about the weather',
version: '1.0.0',
})
export class McpService extends SquidService {
@mcpAuthorizer()
async authorizeMcp(request: McpAuthorizationRequest): Promise<boolean> {
// Implement authorization logic here
// For example, check if the request has a valid token
const token = request.headers['authorization'];
return token === 'valid-token';
}
}

Next steps

To use your MCP server in a Squid application, you must add an MCP connector and link it to your AI agent's abilities.

  • For more information on MCP connectors, check out the documentation.
  • For more information on abilities, check out the documentation.