API Reference
This document provides a complete reference for themcp-use/server API, including all classes, methods, and type definitions.
Server Creation
createMCPServer()
Creates a new MCP server instance with Express integration.
name(string) - Unique identifier for your serverconfig(Partial<ServerConfig>) - Optional configuration object
McpServerInstance - Server instance with both MCP and Express methods
Example:
Server Configuration
ServerConfig
Configuration object for server initialization.
Core Server Methods
server.tool()
Registers a tool that clients can invoke.
definition(ToolDefinition) - Tool configuration and handler
server.resource()
Registers a static resource that clients can read.
definition(ResourceDefinition) - Resource configuration and content
server.resourceTemplate()
Registers a dynamic resource template with parameters.
definition(ResourceTemplateDefinition) - Template configuration
server.prompt()
Registers a prompt template for AI models.
definition(PromptDefinition) - Prompt configuration and generator
server.uiResource()
Registers a UI widget as both a tool and resource.
definition(UIResourceDefinition) - UI widget configuration
server.listen()
Starts the HTTP server with MCP endpoints.
port(number, optional) - Port to listen on (default: 3000)
Type Definitions
ToolDefinition
Configuration for tools.
ResourceDefinition
Configuration for static resources.
ResourceTemplateDefinition
Configuration for dynamic resource templates.
PromptDefinition
Configuration for prompt templates.
UIResourceDefinition
Configuration for UI widgets.
InputDefinition
Parameter definition for tools and prompts.
ResourceAnnotations
Metadata annotations for resources.
WidgetProps
Property definitions for UI widgets.
AppsSdkMetadata
OpenAI Apps SDK metadata for widgets.
Express Integration
The server instance proxies all Express methods, allowing you to use Express functionality directly:Common Express Methods
Example Express Usage
Return Types
CallToolResult
Tool execution result.
ReadResourceResult
Resource read result.
PromptResult
Prompt generation result.
Utility Functions
UI Resource Helpers
The framework provides utility functions for creating UI resources:Error Handling
The framework handles errors gracefully:Best Practices
- Use TypeScript - Leverage type safety for better development experience
- Handle Errors - Always handle errors gracefully in callbacks
- Validate Input - Validate parameters in tool callbacks
- Use Annotations - Provide metadata for better client integration
- Chain Methods - Use fluent API for cleaner code
- Document Tools - Provide clear descriptions for all tools and resources
Next Steps
- Tools Guide - Advanced tool patterns
- Resources Guide - Resource management
- UI Widgets - Building interactive widgets
- Examples - Real-world implementations