Fire in da houseTop Tip:Paying $100+ per month for Perplexity, MidJourney, Runway, ChatGPT and other tools is crazy - get all your AI tools in one site starting at $15 per month with Galaxy AI Fire in da houseCheck it out free

mcp-workers-ai

MCP.Pizza Chef: xtuc

mcp-workers-ai is an MCP server SDK designed specifically for Cloudflare Workers, allowing developers to deploy and manage AI tools in a scalable, serverless environment. It facilitates loading and calling various MCP server tools, such as GitLab and Slack integrations, directly within Cloudflare's edge network. This SDK streamlines the process of integrating real-time AI context and tool invocation into applications, leveraging Cloudflare Workers' global infrastructure for low-latency and high-availability AI-enhanced workflows.

Use This MCP server To

Deploy MCP servers on Cloudflare Workers for edge AI Integrate GitLab and Slack tools in serverless environments Enable scalable AI tool invocation with low latency Manage AI context and tool calls in distributed apps Build serverless AI-enhanced workflows on Cloudflare Load and call multiple MCP tools in edge functions

README

MCP Workers AI

MCP servers sdk for Cloudflare Workers

Usage

Install:

yarn add mcp-workers-ai
# or
npm install -S mcp-workers-ai

Load the MCP server tools:

import { loadTools } from "mcp-workers-ai"

const tools = await loadTools([
  import("@modelcontextprotocol/server-gitlab"),
  import("@modelcontextprotocol/server-slack"),
  ...
]);

// Pass `tools` to the LLM inference request.

Call a tool:

import { callTool } from "mcp-workers-ai"

// Typically the LLM selects a tool to use.
const selected_tool = {
  arguments: {
    project_id: 'svensauleau/test',
    branch: 'main',
    files: [ ... ],
    commit_message: 'added unit tests'
  },
  name: 'push_files'
};

const res = await callTool(selected_tool)

// Pass `res` back into a LLM inference request.

Demo

wrangler configuration:

name = "test"
main = "src/index.ts"

[ai]
binding = "AI"

[vars]
GITLAB_PERSONAL_ACCESS_TOKEN = "glpat-aaaaaaaaaaaaaaaaaaaa"

[alias]
"@modelcontextprotocol/sdk/server/index.js" = "mcp-workers-ai/sdk/server/index.js"
"@modelcontextprotocol/sdk/server/stdio.js" = "mcp-workers-ai/sdk/server/stdio.js"

Worker:

import { loadTools, callTool } from "mcp-workers-ai"

export default {
  async fetch(request: Request, env: any): Promise<Response> {
    // Make sure to set the token before importing the tools
    process.env.GITLAB_PERSONAL_ACCESS_TOKEN = env.GITLAB_PERSONAL_ACCESS_TOKEN;

    const tools = await loadTools([
      import("@modelcontextprotocol/server-gitlab/dist/"),
    ]);

    const prompt = await request.text();

    const response = await env.AI.run(
      "@hf/nousresearch/hermes-2-pro-mistral-7b",
      {
        messages: [{ role: "user", content: prompt }],
        tools,
      },
    );

    if (response.tool_calls && response.tool_calls.length > 0) {
      const selected_tool = response.tool_calls[0];
      const res = await callTool(selected_tool)

      if (res.content.length > 1) {
        throw new Error("too many responses")
      }

      const finalResponse = await env.AI.run(
        "@hf/nousresearch/hermes-2-pro-mistral-7b",
        {
          messages: [
            {
              role: "user",
              content: prompt,
            },
            {
              role: "assistant",
              content: "",
              tool_call: selected_tool.name,
            },
            {
              role: "tool",
              name: selected_tool.name,
              content: res.content[0].text,
            },
          ],
          tools,
        },
      );
      return new Response(finalResponse.response);

    } else {
      return new Response(response.response);
    }
  }
};

Calling the AI:

$ curl http://example.com \
  -d "create a file called 'joke.txt' in my svensauleau/test project with your favorite joke on the main branch. Use the commit message 'added unit tests'"

I have successfully added a file called 'joke.txt' with a joke to your project 'svensauleau/test' on the main branch. The commit message used was 'added unit tests'. You can view the commit and the file in your project's repository.

Result: demo

mcp-workers-ai FAQ

How do I install mcp-workers-ai?
You can install it via npm with 'npm install -S mcp-workers-ai' or yarn with 'yarn add mcp-workers-ai'.
How do I load MCP server tools using mcp-workers-ai?
Use the 'loadTools' function and pass an array of tool imports, e.g., GitLab or Slack MCP servers.
How do I call a specific MCP tool with mcp-workers-ai?
Use the 'callTool' function with the selected tool's name and arguments to invoke it and get the response.
Can mcp-workers-ai be used to deploy MCP servers globally?
Yes, it leverages Cloudflare Workers' global edge network for scalable, low-latency MCP server deployments.
What environment variables are needed for mcp-workers-ai?
Environment variables depend on the tools used, e.g., GITLAB_PERSONAL_ACCESS_TOKEN for GitLab integration.
Is mcp-workers-ai compatible with other MCP servers?
Yes, it supports loading and calling any MCP server tools compatible with the MCP protocol.
Does mcp-workers-ai support asynchronous tool calls?
Yes, tool calls are asynchronous to handle network and processing latency efficiently.
How do I configure mcp-workers-ai in a Cloudflare Worker project?
Configure your wrangler.toml with bindings and environment variables, then import and use the SDK in your worker code.