> ## Documentation Index
> Fetch the complete documentation index at: https://docs.xano.com/llms.txt
> Use this file to discover all available pages before exploring further.

# XanoScript for MCP Servers

> Define MCP servers in XanoScript to create intelligent agents and assistants

export const xanoscriptApiInputsDiagram = `
\`\`\`mermaid
flowchart TB
    A[Declaration] --> B[Input]
    B --> C[Stack]
    C --> D[Response]
    D --> E[Settings]
    style A fill:#cdeaff,stroke:#0077cc,stroke-width:2px
    style B fill:#f5f5f5,stroke:#ccc,stroke-width:1px
    style C fill:#f5f5f5,stroke:#ccc,stroke-width:1px
    style D fill:#f5f5f5,stroke:#ccc,stroke-width:1px
    style E fill:#f5f5f5,stroke:#ccc,stroke-width:1px
\`\`\`
`;

export function SideBySide({diagram, children}) {
  return <div style={{
    display: "flex",
    gap: "1rem",
    alignItems: "flex-start",
    flexWrap: "wrap"
  }}>
      <div style={{
    flex: "0 0 180px",
    minWidth: "150px"
  }}>
        <div>{mdx(diagram)}</div>
      </div>
      <div style={{
    flex: 1
  }}>
        {children}
      </div>
    </div>;
}

export const HoverImageCode = ({src, alt = "", width = "100%", maxWidth = "800px", className = "", defaultOpen = false, openOnHover = true, children}) => {
  const [open, setOpen] = useState(defaultOpen);
  const panelRef = useRef(null);
  const [maxHeight, setMaxHeight] = useState(0);
  useEffect(() => {
    if (panelRef.current) {
      setMaxHeight(open ? panelRef.current.scrollHeight : 0);
    }
  }, [open, children]);
  const handleMouseEnter = () => openOnHover && setOpen(true);
  const handleMouseLeave = () => openOnHover && setOpen(false);
  const handleClick = () => setOpen(s => !s);
  const handleImageClick = e => {
    e.stopPropagation();
    e.preventDefault();
    handleClick();
  };
  const prefersReducedMotion = typeof window !== "undefined" && window.matchMedia && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
  const transition = prefersReducedMotion ? "none" : "max-height 300ms ease, opacity 300ms ease, transform 300ms ease";
  return <div className={`border rounded-md overflow-hidden ${className}`} style={{
    width,
    maxWidth
  }} onMouseEnter={handleMouseEnter} onMouseLeave={handleMouseLeave}>
      {}
      <div role="button" tabIndex={0} aria-label="Toggle code" aria-expanded={open} style={{
    cursor: "pointer"
  }}>
        <img src={src} alt={alt} onClickCapture={e => {
    e.stopPropagation();
    e.preventDefault();
    handleClick();
  }} style={{
    display: "block",
    width: "100%",
    height: "auto"
  }} />
      </div>

      {}
      <div className="not-prose" ref={panelRef} style={{
    overflow: "hidden",
    maxHeight: `${maxHeight}px`,
    opacity: open ? 1 : 0,
    transform: open ? "translateY(0)" : "translateY(-6px)",
    transition
  }}>
        <div style={{
    padding: "0.75rem"
  }}>{children}</div>
      </div>
    </div>;
};

## Introduction

The `mcp_server` primitive lets you define MCP servers using XanoScript.

Each MCP server corresponds to a **collection of tools** that an AI agent can access to perform specific tasks with your Xano backend — expressed in code.

MCP servers will typically:

* Declare their **name** and **description**
* Include **instructions** for the AI agent
* Reference **existing tools** in your workspace
* Support **tagging** for organization

***

## Anatomy

Every XanoScript MCP server follows a predictable structure.

Unlike other primitives, MCP servers are not split into multiple sections. Instead, they have a single block that contains all of the information needed to define the server.

Here's an example of a fully defined MCP server in XanoScript:

```javascript XanoScript lines icon="code" theme={null}
// Handles basic database operations
mcp_server "My MCP Server" {
  canonical = "-T6UaAe0"
  instructions = "This MCP server is designed to handle basic database operations, such as retrieving, updating, adding, and deleting records. Process user queries with the available tools to complete their request to the best of your ability. Do not assume anything about the operation the user is requesting; ask for clarification before execution if necessary."
  tags = ["database"]
  tools = [{name: "get_user_record"}]
}
```

***

## Parameter definition

| Parameter      | Required | Description                                                                                                                                                                                                                                                                                                                                                                               |
| -------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `description`  | no       | A short summary of the mcp server. May also appear as a “//” comment above the block.                                                                                                                                                                                                                                                                                                     |
| `instructions` | no       | Instructions for LLMs using the server. While this field is not required, it is strongly encouraged to be used to help LLMs understand the server and its purpose.                                                                                                                                                                                                                        |
|                |          | **Example:** `instructions = "This MCP server is designed to handle basic database operations, such as retrieving, updating, adding, and deleting records. Process user queries with the available tools to complete their request to the best of your ability. Do not assume anything about the operation the user is requesting; ask for clarification before execution if necessary."` |
| `tags`         | no       | A list of tags used to categorize and organize the server in your workspace.                                                                                                                                                                                                                                                                                                              |
|                |          | **Example:** `tags = ["database"]`                                                                                                                                                                                                                                                                                                                                                        |
| `tools`        | ✅        | A list of tools that the server will reference.                                                                                                                                                                                                                                                                                                                                           |
|                |          | **Example:** `tools = [{name: "get_user_record"}]`                                                                                                                                                                                                                                                                                                                                        |

***

## What's Next

Now that you understand how to define MCP servers in XanoScript, here are a few great next steps:

<Card title="Learn about AI Tools" icon="hammer" horizontal href="/xanoscript/ai-tools">
  Create the tools that your MCP server will reference and make available to AI agents.
</Card>

<Card title="Try it out in VS Code" icon="https://mintcdn.com/xano-997cb9ee/aZQYcxhIvSDTNEim/images/icons/vscode.svg?fit=max&auto=format&n=aZQYcxhIvSDTNEim&q=85&s=bb6c91058fcbe6ee28fcda04e03de2e6" horizontal href="/xanoscript/vs-code" width="100" height="100" data-path="images/icons/vscode.svg">
  Use the XanoScript VS Code extension with Copilot to write XanoScript in your favorite IDE.
</Card>
