# How to Set Up MCP Integration in OpenAI Plugins: Client and Server Implementation

> Learn to set up MCP integration in OpenAI plugins. Use @ai-sdk/mcp to connect clients to endpoints, retrieve tools, and enable automatic tool invocation for your plugins.

- Repository: [OpenAI/plugins](https://github.com/openai/plugins)
- Tags: how-to-guide
- Published: 2026-06-16

---

**To set up MCP integration in OpenAI plugins, use `@ai-sdk/mcp` to create a client that connects to a Streamable HTTP endpoint, retrieve tools with `mcpClient.tools()`, and pass them to `generateText()` for automatic tool invocation.**

The OpenAI plugins repository implements the Model Context Protocol (MCP) to enable AI agents to discover and invoke external tools without hard-coding API details. This standardized protocol allows developers to connect to remote MCP servers like the Vercel-hosted endpoint, or build custom servers on platforms like Cloudflare Workers. Understanding how to set up MCP integration in the `openai/plugins` repository requires familiarity with both client-side consumption and server-side exposure patterns.

## Understanding MCP Architecture in OpenAI Plugins

According to the source code analysis of `openai/plugins`, the MCP surface operates through three complementary layers that handle different aspects of tool communication and discovery.

### The Three-Layer Architecture

The implementation spans client integration, server exposure, and server implementation:

- **MCP client integration**: Agents use the `@ai-sdk/mcp` package to create clients that discover tools from remote MCP servers and invoke them using schema-validated JSON. This pattern is documented in [`plugins/vercel/skills/ai-sdk/SKILL.md`](https://github.com/openai/plugins/blob/main/plugins/vercel/skills/ai-sdk/SKILL.md).

- **MCP server exposure**: The Vercel plugin provides a built-in MCP server at `https://mcp.vercel.com` that proxies Vercel's REST endpoints as discoverable tools. Configuration details live in [`plugins/vercel/skills/vercel-api/SKILL.md`](https://github.com/openai/plugins/blob/main/plugins/vercel/skills/vercel-api/SKILL.md).

- **MCP server implementation**: Developers can author custom MCP servers using Cloudflare Workers to expose domain-specific tools, as outlined in [`plugins/cloudflare/skills/building-mcp-server-on-cloudflare/SKILL.md`](https://github.com/openai/plugins/blob/main/plugins/cloudflare/skills/building-mcp-server-on-cloudflare/SKILL.md).

### The MCP Request Flow

The protocol follows a four-step execution process:

1. **Discover**: The client calls `mcpClient.tools()` to retrieve tool definitions including names and input/output schemas.

2. **Select**: The AI model receives the tool list and determines which tool satisfies the user request.

3. **Invoke**: The model emits a tool call; the client validates arguments against Zod schemas and forwards the request via Streamable HTTP transport.

4. **Result**: The server returns structured response content that the model incorporates into its answer.

## Setting Up the MCP Client

To consume MCP-exposed capabilities in your plugin, instantiate a client using the `@ai-sdk/mcp` package. The following example from [`plugins/vercel/skills/ai-sdk/SKILL.md`](https://github.com/openai/plugins/blob/main/plugins/vercel/skills/ai-sdk/SKILL.md) demonstrates connecting to Vercel's MCP server:

```typescript
import { generateText } from "ai";
import { createMCPClient } from "@ai-sdk/mcp";

// Initialize the MCP client with Streamable HTTP transport
const mcpClient = await createMCPClient({
  transport: {
    type: "streamable-http",
    url: "https://mcp.vercel.com",
  },
});

// Retrieve available tools from the server
const tools = await mcpClient.tools();

// Pass tools to the LLM for automatic selection and invocation
const result = await generateText({
  model: "openai/gpt-4o-mini",
  tools,
  prompt: "Show me the last three deployments for the project 'my-site'.",
});

await mcpClient.close();
console.log(result.output);

```

The `createMCPClient` function accepts a transport configuration specifying the `type` as `"streamable-http"` and the target `url`. The `tools()` method returns a set of MCP-aware tools that can be passed directly to `generateText` or `streamText` functions from the AI SDK.

## Building a Custom MCP Server on Cloudflare Workers

For custom tool implementations, you can author MCP servers using Cloudflare Workers. The implementation uses the `McpAgent` class from the `agents/mcp` package, as documented in [`plugins/cloudflare/skills/building-mcp-server-on-cloudflare/SKILL.md`](https://github.com/openai/plugins/blob/main/plugins/cloudflare/skills/building-mcp-server-on-cloudflare/SKILL.md).

Create the server implementation in [`src/mcp.ts`](https://github.com/openai/plugins/blob/main/src/mcp.ts):

```typescript
import { McpAgent } from "agents/mcp";
import { z } from "zod";

export class MyMCP extends McpAgent {
  server = new Server({ name: "my-mcp", version: "1.0.0" });

  async init() {
    // Define tools with Zod schemas for input validation
    this.server.tool(
      "add",
      { a: z.number(), b: z.number() },
      async ({ a, b }) => ({
        content: [{ type: "text", text: String(a + b) }],
      })
    );

    this.server.tool(
      "get_weather",
      { city: z.string() },
      async ({ city }) => {
        const res = await fetch(`https://api.weather.com/${city}`);
        const data = await res.json();
        return {
          content: [{ type: "text", text: JSON.stringify(data) }],
        };
      }
    );
  }
}

```

Then expose the server via Streamable HTTP in [`src/index.ts`](https://github.com/openai/plugins/blob/main/src/index.ts):

```typescript
import { MyMCP } from "./mcp";

export default {
  async fetch(request: Request, env: Env, ctx: ExecutionContext) {
    const url = new URL(request.url);
    if (url.pathname === "/mcp") {
      return MyMCP.serveStreamableHTTP("/mcp").fetch(request, env, ctx);
    }
    return new Response("MCP Server ready", { status: 200 });
  },
};

export { MyMCP };

```

Deploy with `wrangler deploy`. Clients can then connect to your custom endpoint using the same `createMCPClient` pattern with your Worker URL.

## Practical Example: Auditing Vercel Projects with MCP Tools

The Vercel plugin exposes tools for project management, environment variables, and deployment logs. As detailed in [`plugins/vercel/skills/vercel-api/SKILL.md`](https://github.com/openai/plugins/blob/main/plugins/vercel/skills/vercel-api/SKILL.md), you can orchestrate multi-step audits without manual scripting:

```typescript
import { generateText } from "ai";
import { createMCPClient } from "@ai-sdk/mcp";

const client = await createMCPClient({
  transport: { type: "streamable-http", url: "https://mcp.vercel.com" },
});

const tools = await client.tools();

const audit = await generateText({
  model: "openai/gpt-4o",
  tools,
  prompt: `
    1. List the environment variables for project "my-app".
    2. Show any domains that are not verified.
    3. Pull the latest deployment logs.
  `,
});

await client.close();
console.log(audit.output);

```

The MCP server handles OAuth token management internally, allowing agents to perform read-only queries without exposing credentials in the application code.

## Summary

- **Initialize clients** using `createMCPClient` from `@ai-sdk/mcp` with `streamable-http` transport to connect to MCP servers like `https://mcp.vercel.com`.
- **Discover tools** by calling `mcpClient.tools()`, which returns schema-validated tool definitions that can be passed directly to AI SDK generation functions.
- **Implement custom servers** by extending `McpAgent`, registering tools with `server.tool(name, schema, handler)`, and exposing endpoints via `serveStreamableHTTP`.
- **Leverage automatic auth**: The MCP client manages OAuth flows and token refresh internally, eliminating manual token management from your integration code.
- **Reference implementation files** in [`plugins/vercel/skills/ai-sdk/SKILL.md`](https://github.com/openai/plugins/blob/main/plugins/vercel/skills/ai-sdk/SKILL.md) for client patterns and [`plugins/cloudflare/skills/building-mcp-server-on-cloudflare/SKILL.md`](https://github.com/openai/plugins/blob/main/plugins/cloudflare/skills/building-mcp-server-on-cloudflare/SKILL.md) for server authoring.

## Frequently Asked Questions

### What is the Model Context Protocol (MCP) in OpenAI plugins?

The Model Context Protocol (MCP) is a standardized interface that allows AI agents to discover and invoke external tools without hard-coding API details. In the `openai/plugins` repository, MCP enables seamless integration between AI agents and external services like Vercel through schema-validated JSON over Streamable HTTP transport.

### How does authentication work when connecting to an MCP server?

According to the source code in [`plugins/vercel/skills/ai-sdk/SKILL.md`](https://github.com/openai/plugins/blob/main/plugins/vercel/skills/ai-sdk/SKILL.md), the `@ai-sdk/mcp` client handles OAuth internally, automatically refreshing tokens as needed. This zero-token-management approach allows agents to perform authorized queries without embedding credentials in the application code.

### Can I expose my own tools using MCP in OpenAI plugins?

Yes, you can build custom MCP servers using the patterns documented in [`plugins/cloudflare/skills/building-mcp-server-on-cloudflare/SKILL.md`](https://github.com/openai/plugins/blob/main/plugins/cloudflare/skills/building-mcp-server-on-cloudflare/SKILL.md). By extending the `McpAgent` class and registering tools with the `server.tool()` method, you can expose domain-specific capabilities via Streamable HTTP endpoints that any MCP client can consume.

### What transport protocol does MCP use in the OpenAI plugins repository?

The implementation uses **Streamable HTTP** (SSE-style) transport, configured by setting `type: "streamable-http"` in the client transport options. This stateless transport is used for both the Vercel MCP server (`https://mcp.vercel.com`) and custom Cloudflare Worker implementations, as specified in the respective skill documentation files.