> For the complete documentation index, see [llms.txt](https://ai.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ai.ortusbooks.com/model-context-protocol-mcp/server/registration.md).

# Registering Tools, Resources & Prompts

Register capabilities that your MCP server exposes to clients.

## Tool Registration

### Register a Single Tool

```javascript
server = MCPServer( "myApp" )
    .registerTool(
        aiTool( "getWeather", "Get current weather for a location", ( location ) => {
            return weatherService.getCurrent( location )
        } )
        .describeArg( "location", "City name or coordinates" )
    )
```

### Register Multiple Tools

```javascript
tools = [
    aiTool( "search", "Search documents", searchHandler ),
    aiTool( "translate", "Translate text", translateHandler ),
    aiTool( "summarize", "Summarize text", summarizeHandler )
]

server = MCPServer( "myApp" )
    .registerTools( tools )
```

### Check & Retrieve Tools

```javascript
// Check if a tool exists
exists = server.hasTool( "search" )

// Get a specific tool
tool = server.getTool( "search" )

// Get tool count
count = server.getToolCount()

// Get all tools
tools = server.getTools()

// List tools (MCP format)
toolsList = server.listTools()
// [
//     {
//         name: "search",
//         description: "Search documents",
//         inputSchema: { ... }
//     }
// ]
```

### Unregister Tools

```javascript
// Remove a specific tool
server.unregisterTool( "oldTool" )

// Remove all tools
server.clearTools()
```

## Resource Registration

Resources provide access to documents and data.

### Register a Resource

```javascript
server = MCPServer( "myApp" )
    .registerResource(
        uri: "docs://readme",
        name: "README",
        description: "Project documentation",
        mimeType: "text/markdown",
        handler: () => {
            return fileRead( expandPath( "/readme.md" ) )
        }
    )
```

### Register Dynamic Resources

```javascript
// Database content
server.registerResource(
    uri: "db://users",
    name: "User List",
    description: "Current user data",
    mimeType: "application/json",
    handler: () => {
        return userService.getAllUsers()
    }
)

// Configuration
server.registerResource(
    uri: "config://app",
    name: "App Configuration",
    description: "Application settings",
    mimeType: "application/json",
    handler: () => {
        return application.settings
    }
)
```

### List and Read Resources

```javascript
// List available resources
resources = server.listResources()

// Check if resource exists
exists = server.hasResource( "docs://readme" )

// Read a resource
content = server.readResource( "docs://readme" )
// {
//     contents: [
//         {
//             uri: "docs://readme",
//             mimeType: "text/markdown",
//             text: "# Readme content..."
//         }
//     ]
// }
```

### Manage Resources

```javascript
// Remove a resource
server.unregisterResource( "docs://readme" )

// Clear all resources
server.clearResources()
```

## Prompt Registration

Prompts provide reusable prompt templates for AI clients.

### Register a Prompt

````javascript
server = MCPServer( "myApp" )
    .registerPrompt(
        name: "codeReview",
        description: "Code review prompt template",
        args: [
            { name: "language", description: "Programming language", required: true },
            { name: "code", description: "Code to review", required: true }
        ],
        handler: ( args ) => {
            return [
                {
                    role: "system",
                    content: "You are a code reviewer specializing in #args.language#."
                },
                {
                    role: "user",
                    content: "Please review this code:\n\n```#args.language#\n#args.code#\n```"
                }
            ]
        }
    )
````

### List and Get Prompts

```javascript
// List available prompts
prompts = server.listPrompts()

// Check if prompt exists
exists = server.hasPrompt( "codeReview" )

// Get a prompt with arguments
result = server.getPrompt( "codeReview", {
    language: "java",
    code: "public void test() {}"
} )
// {
//     description: "Code review prompt template",
//     messages: [
//         { role: "system", content: { type: "text", text: "..." } },
//         { role: "user", content: { type: "text", text: "..." } }
//     ]
// }
```

## Fluent Registration Pattern

All registration methods return `this` for chaining:

```javascript
server = MCPServer( "myApp" )
    .setDescription( "Complete server" )
    .setVersion( "1.0.0" )

    // Register tools
    .registerTool( searchTool )
    .registerTool( calculateTool )

    // Register resources
    .registerResource(
        uri: "docs://readme",
        name: "README",
        description: "Documentation",
        mimeType: "text/markdown",
        handler: () => fileRead( "./readme.md" )
    )

    // Register prompts
    .registerPrompt(
        name: "reviewer",
        description: "Code review",
        args: [ { name: "code", required: true } ],
        handler: ( args ) => [
            { role: "system", content: "Review this code." },
            { role: "user", content: args.code }
        ]
    )

    // Configure security
    .withBasicAuth( "admin", "secret" )
    .withCors( "https://example.com" )
```

## Next Steps

* 📋 [Annotation-Based Discovery](/model-context-protocol-mcp/server/annotation-discovery.md) — Auto-register with @mcpTool
* 🏗️ [Class-Based Servers](/model-context-protocol-mcp/server/class-based-servers.md) — Organize in a class
* 💡 [Examples](https://github.com/ortus-boxlang/bx-ai-docs/blob/v2.x/_examples.md) — Complete working examples


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://ai.ortusbooks.com/model-context-protocol-mcp/server/registration.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
