MCP Tools Overview
Learn about MCP (Model Context Protocol) tools and how they enable AI assistants to interact with your application
MCP Tools Overview
MCP (Model Context Protocol) tools allow AI assistants like ChatGPT to interact with your application's data and functionality. These tools act as bridges between AI models and your backend systems.
What are MCP Tools?
MCP tools are functions that AI models can call to:
- Query data from your database (users, organizations, payments)
- Execute operations (send emails, update records, trigger workflows)
- Access real-time information that isn't in the model's training data
- Perform actions on behalf of authenticated users
How MCP Works
┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ ChatGPT │────▶│ MCP Server │────▶│ Your API │
│ Client │◄────│ (Route) │◄────│ (Tools) │
└─────────────┘ └─────────────┘ └─────────────┘- User asks ChatGPT a question that requires data from your app
- ChatGPT decides which MCP tool to call based on the tool's description
- MCP Server receives the request and validates authentication
- Your Tool executes the logic and returns data
- ChatGPT formats the response for the user
Built-in Admin Tools
The starter kit includes a set of admin tools available at /api/adminx/mcp:
| Tool | Description |
|---|---|
get_admin_stats | Get comprehensive statistics about users, organizations, payments, and sessions |
get_user_by_email | Look up a user by their email address |
get_user_by_id | Retrieve user information by ID |
list_users | List all users with optional pagination |
list_organizations | List all organizations |
get_payment_records | Retrieve payment transaction history |
get_payments_by_email | Get payments for a specific user |
get_active_sessions | List currently active user sessions |
get_organization_by_id | Retrieve organization details by ID |
Tool Structure
Each MCP tool follows a consistent pattern:
server.tool(
"tool_name", // Unique identifier
"Tool description", // Description for the AI model
{ // Zod schema for parameters
param1: z.string(),
param2: z.number().optional(),
},
async ({ param1, param2 }) => {
// Tool implementation
return {
content: [
{
type: "text",
text: JSON.stringify(result, null, 2),
},
],
};
},
);Authentication
MCP tools can be protected using your existing auth system:
import { auth } from "@repo/auth/server";
import { headers } from "next/headers";
async function requireAuth() {
const session = await auth.api.getSession({
headers: await headers(),
});
if (!session?.user?.id) {
throw new Error("Unauthorized");
}
return session;
}Next Steps
- Registering Custom Tools - Learn how to add your own MCP tools
- ChatGPT SDK Overview - Overview of the ChatGPT SDK integration