Using MCP Actions in SpinAI

SpinAI’s integration with Model Context Protocol (MCP) allows you to seamlessly incorporate powerful platform actions into your AI agents. MCP actions work just like regular SpinAI actions, and can be composed with other actions in your agent’s toolkit.

This is extremely powerful because it has the potential to give your AI agents a whole toolbox of actions without writing any code yourself.

Currently, we support all MCPs available on Smithery’s MCP registry.

Installing a MCP (from Smithery)

To install an MCP locally, it’s as easy as running our npx spinai-mcp helper function.

For example:

npx spinai-mcp install @smithery-ai/github --provider smithery

To include environment variables:

npx spinai-mcp install @smithery-ai/github --provider smithery --config "{\"githubPersonalAccessToken\":\"move_my_token_to_a_dot_env_after\"}"

Providers

Right now we currently support MCPs from:

Using your MCP with a SpinAI Agent

Example code:

import mcpConfig from "../mcp-config.ts";

dotenv.config();

async function main() {
  // Create actions from MCP configuration
  console.log("Setting up MCP actions...");
  const mcpActions = await createActionsFromMcpConfig({
    config: mcpConfig,
    envMapping: {
      githubPersonalAccessToken: process.env.GITHUB_TOKEN,
    },
  });

  const agent = createAgent({
    instructions: `You are a GitHub assistant that can help with repository management.
    Use the available GitHub actions to help users with their requests.`,
    actions: [...mcpActions], // you can add other MCP actions or regular SpinAI actions here as well!
    model: openai("gpt-4o"),
  });

To use your MCP actions within your SpinAI Agent, you can simply use the createActionsFromMcpConfig function to convert them to regular SpinAI Actions.

ParameterTypeDescription
configMcpConfigThe MCP config file (mcp-config.ts).
envMappingRecord<string, string | undefined>Environment variable mappings to apply to all MCPs. Format: { "MCP_VAR_NAME": process.env.myVariable }. If this AND one in mcp-config.ts are passed in, it will prioritize this one.
excludedActionsstring[]IDs of actions to exclude.
includedActionsstring[]IDs of actions to include (if empty, all actions except excluded ones are included).