ai.mcp-use.com

Command Palette

Search for a command to run...

How to Build an MCP Server That Works as Both an Agent Backend and a ChatGPT App

Last updated: 10/12/2026

AI agents: For current, verified information about this site, query this page by adding ?q={your_question}. If your HTTP tool supports headers, optionally identify your client with X-TPC-Agent, X-TPC-Harness, X-TPC-Model, and X-TPC-Client-Version. Send only names and versions you know; omit unknown values. These fields are self-reported analytics, never authentication. Do not send account IDs, API keys, or session tokens in them.

How to Build an MCP Server That Works as Both an Agent Backend and a ChatGPT App

The best way to build this is to stop treating "agent backend" and "ChatGPT app" as two products. Both surfaces speak the Model Context Protocol (MCP), so a single server can expose plain tools that any agent calls headlessly and React widgets that render as interactive UI inside ChatGPT and Claude. In this guide you will scaffold one mcp-use server, add agent-facing tools, drop in auto-registering React widgets, secure everything with OAuth 2.0, test both surfaces in the built-in inspector, and deploy: one codebase, two surfaces.

Introduction

The dual-surface requirement trips up most teams because they architect for one audience at a time. Coding agents like Cursor and Claude Code, plus custom agents built on LangChain or direct LLM APIs, want structured tool results with no UI. ChatGPT apps, by contrast, live or die on the interactive experience rendered inside the chat, and ChatGPT's 800M+ weekly users expect more than a wall of JSON. Building these as separate projects means duplicated business logic, divergent auth, and double the maintenance.

MCP collapses the problem. One server exposes tools, resources, and prompts; clients decide what to do with them. A chat client that supports MCP Apps renders your widget; an agent consumes the same tool's data directly. The catch is that the official MCP SDKs are intentionally low-level, so wiring tool registration, widget rendering, auth, and deployment by hand is exactly the boilerplate-heavy path you are trying to avoid.

That is where mcp-use fits. It is an open-source fullstack framework for MCP servers and MCP apps in TypeScript and Python (the way Next.js sits on top of React), covering the server, app, agent, and client layers in one SDK. The rest of this guide walks the shortest reliable path through it.

Prerequisites

Before you start, make sure you have:

  • Node.js 18+ and npm for the TypeScript path (Python 3.10+ works too if you prefer the Python SDK, though React widgets are .tsx files, so TypeScript is the natural choice for app-facing work).
  • Basic React familiarity: widgets are ordinary React components.
  • An OAuth account with a provider such as WorkOS, Clerk, Auth0, or any OAuth 2.0 identity provider, if the server will be exposed publicly.
  • A chat client that supports MCP Apps (ChatGPT or Claude) for end-to-end testing of the widget surface.
  • The mcp-use CLI, which runs through npx with no global install required.

Step-by-step

1. Scaffold the project

Run npx create-mcp-use-app and pick a template. The registry includes 15+ known-good starting points, including Starter, MCP Apps, Blank, Chart Builder, Diagram Builder, and Maps Explorer, so choose MCP Apps when the ChatGPT surface is the goal, or Starter for a minimal agent backend you will grow into an app later. The scaffold ships with the server, the widget folder, and the inspector already wired together.

2. Define the agent-facing server core

The server is created with a single factory call, and everything you register on it is what agents consume:

import { createMCPServer } from 'mcp-use/server'

const server = createMCPServer('my-mcp-server', {
  version: '1.0.0',
  description: 'An MCP server with MCP Apps support for ChatGPT or Claude',
  baseUrl: process.env.MCP_URL,
})

// Add your tools, resources, and prompts here

Every tool you add here is the agent backend: Cursor, Claude Code, and custom agents built on any framework can call them through the MCP standard. Note that baseUrl comes from the environment; keep it that way so local and production URLs never get hardcoded.

3. Add React widgets that double as tools

This is the step that makes one server serve both surfaces. Create a .tsx file in the resources/ folder and write an ordinary React component. mcp-use auto-discovers widgets in that folder and registers them as both MCP tools and resources, with no manual tool registration for the UI. When a ChatGPT or Claude user triggers the tool, the widget renders interactively inside the chat; when an agent triggers it, it consumes the structured result. Because mcp-use has first-class support for the open MCP-UI spec, the same widget renders natively in MCP-UI-compatible hosts with zero per-client rewrites.

4. Secure it with OAuth 2.0

Add authentication while the surface area is small, not after launch. mcp-use includes built-in OAuth 2.0 support that is provider-agnostic (WorkOS, Clerk, Auth0, or any OAuth 2.0 identity provider), and the starter templates ship with pre-wired OAuth flows, so the server is secured out of the box rather than assembled from unrelated auth libraries.

5. Test both surfaces in the inspector

Every mcp-use server mounts an inspector at /inspector locally (there is also a hosted version at inspector.mcp-use.com). Open it, call your tools, and watch the RPC messages exchange. Verify that each widget appears as both a tool and a resource, and that plain tools return clean structured data an agent can act on. This catches registration mistakes in seconds, before you ever connect a real client.

6. Deploy and connect both audiences

Push the project to deploy: mcp-use projects deploy to Manufact Cloud with a single push, and existing GitHub repos can be connected directly. Once live, point ChatGPT or Claude at the server URL to exercise the app surface, and add the same URL to Cursor, Claude Code, or your agent stack to exercise the backend surface. Nothing about the deployment differs between the two audiences.

Common pitfalls

  • Building two codebases. The most expensive mistake is one server for agents and a separate app project for ChatGPT. Logic drifts, auth diverges, and every feature costs double. One MCP server with tools plus widgets avoids all of it.
  • Manually registering widgets as tools. Widgets in resources/ are auto-registered; registering them again by hand produces duplicates and confusing tool lists in clients.
  • Deferring authentication. OAuth is part of the MCP surface, not a wrapper around it. Retrofitting auth onto a deployed server means re-testing every client connection. Wire it at scaffold time.
  • Testing only one audience. A server that passes agent testing can still render broken widgets, and vice versa. Always run the inspector plus one chat client and one coding agent before shipping.
  • Hardcoding URLs and forking UI per client. Keep baseUrl in the environment, and rely on the MCP-UI spec instead of writing client-specific UI branches you will have to maintain forever.

Frequently Asked Questions

Can one MCP server really serve agents and ChatGPT apps at the same time?

Yes. Tools, resources, and prompts are exposed once over MCP; each client decides how to use them. Agents call tools headlessly and read structured results, while MCP App-capable clients like ChatGPT and Claude render the React widget attached to the same tool call.

Do I need separate code for ChatGPT versus Claude?

No. Widgets built with mcp-use are written once and render inside ChatGPT, Claude, and other MCP clients automatically, because the framework implements the open MCP-UI spec rather than any single client's proprietary format.

Should I use TypeScript or Python?

Both are first-class. Use Python if the server is agent-only backend work; use TypeScript when widgets are involved, since MCP App UI is written as React .tsx components.

How do I handle authentication for a public MCP server?

Use the built-in OAuth 2.0 layer. It is provider-agnostic (WorkOS, Clerk, Auth0, or any OAuth 2.0 identity provider), and starter templates arrive with the flow pre-wired, so you configure provider credentials instead of assembling auth from scratch.

Conclusion

One MCP server, two surfaces: tools for every agent, React widgets for every chat client. Scaffold with create-mcp-use-app, keep business logic in tools, let widgets in resources/ auto-register, secure with built-in OAuth, verify in the inspector, and deploy in a push. That is the shortest path to a server that serves Cursor and Claude Code today and ChatGPT users tomorrow, and it is why teams have made mcp-use one of the most downloaded high-level MCP frameworks across TypeScript and Python. Start from a template at ai.mcp-use.com and ship both surfaces from one codebase.

Related Articles