View the source code for this module on GitHub: https://github.com/mcp-use/mcp-use/blob/main/libraries/typescript/packages/mcp-use/src/server/mcp-server.ts
server.resource(), or register a parameterized family of resources with server.resourceTemplate(). Both methods are members of the MCPServer class and return this, so calls can be chained.
Resource Registration
Registration methods for static and templated resources, plus the related definition and callback types.Methods
server.resource()
Registers a static resource that clients can read at a fixed URI. A resource represents a single addressable piece of content (configuration, a status snapshot, a document) identified by itsuri. The content is produced by a ReadResourceCallback, which may be passed as the second argument or supplied as the readCallback field on the definition.
If neither a callback argument nor a readCallback field is present, registration throws an Error. Resources are keyed internally by `${name}:${uri}`, so a unique name plus uri pair avoids collisions. Use server.resourceTemplate() instead when the URI contains parameters.
Parameters
ReturnsResource configuration object. UseResourceDefinition(with areadCallbackand a requiredmimeType) orResourceDefinitionWithoutCallback(pass the callback as the second argument;mimeTypeis optional and inferred from response helpers).Async function that returns the resource content. Optional whenreadCallbackis set on the definition.
SignatureThe sameMCPServerinstance, for method chaining.
server.resourceTemplate()
Registers a resource template: a family of resources whose URIs share a pattern with{param} placeholders (for example user://{userId}/profile). When a client reads a URI that matches the template, the placeholders are parsed out and passed to the callback. Use this for parameterized reads such as files by path or records by id.
The definition may use the nested shape (ResourceTemplateDefinition / ResourceTemplateDefinitionWithoutCallback, where the URI lives under resourceTemplate.uriTemplate) or the flat shape (FlatResourceTemplateDefinition / FlatResourceTemplateDefinitionWithoutCallback, where uriTemplate sits directly on the object). Supplying an optional Zod schema narrows the params argument of the callback to z.infer<schema>. The read handler is taken from the callback argument or, if omitted, from the readCallback field on the definition; if neither is present, registration throws an Error. Templates are keyed internally by name.
Parameters
ReturnsResource template configuration.Tis one ofResourceTemplateDefinition,ResourceTemplateDefinitionWithoutCallback,FlatResourceTemplateDefinition, orFlatResourceTemplateDefinitionWithoutCallback.Async function receiving the matched URI and extracted parameters. Optional whenreadCallbackis set on the definition.
SignatureThe sameMCPServerinstance, for method chaining.
Types
ResourceDefinition
Configuration object for a static resource registered throughserver.resource(). This is the inline-callback shape: it carries a required mimeType and a readCallback. To pass the callback as the second argument to server.resource() instead, use ResourceDefinitionWithoutCallback, whose mimeType is optional and inferred from response helpers such as text() or object().
The generic parameter HasOAuth is false by default and controls whether ctx.auth is available inside the callback.
Fields
SignatureUnique identifier for the resource. Example:"app-settings".URI pattern for accessing the resource. Use a custom scheme such asconfig://orapp://. Example:"config://app-settings".Human-readable title. Example:"App Settings".Description of what the resource contains.MIME type of the resource content (required for this shape).Optional annotations for discovery and presentation.Async callback that returns the resource content.Arbitrary metadata attached to the resource.Optional completion callbacks.
UIResourceDefinition
Discriminated union describing an interactive UI resource (a widget) for clients that support rich rendering, such as ChatGPT (Apps SDK) and MCP Apps clients. Pass a value of this type toserver.uiResource(). The active member is chosen by the type discriminant: "externalUrl", "rawHtml", "remoteDom", "appsSdk", or "mcpApps". All members extend a common base providing name, title, description, props, size, annotations, encoding (defaults to "text"), exposeAsTool (defaults to true), toolAnnotations, toolOutput, and _meta.
Each member adds its own content fields: externalUrl carries a widget id, rawHtml carries htmlContent, remoteDom carries a script (and optional framework, default "react"), appsSdk carries an htmlTemplate, and mcpApps carries an htmlTemplate plus unified metadata that adapters translate per protocol.
Members
SignatureServes a widget through an iframe (legacy MCP-UI).Renders direct HTML content (legacy MCP-UI).Scripted remote-DOM UI components (legacy MCP-UI).OpenAI Apps SDK compatible widget using thetext/html+skybridgemime type.Official MCP Apps Extension (SEP-1865) widget with dual-protocol support.
ReadResourceCallback
The async handler that produces the content for a static resource. It receives a singlectx argument (an EnhancedResourceContext) carrying request context and a client capability checker, and returns a promise resolving to a CallToolResult (the shape returned by response helpers like text() and object()) or a ReadResourceResult (the older API shape). The generic HasOAuth controls whether ctx.auth is available.
Parameters
ReturnsRequest context withreq,client(capability checker), and, when OAuth is configured,auth.
SignatureThe resource content.
ReadResourceTemplateCallback
The async handler that produces content for a resource template. It is an overloaded union of four signatures so handlers can take only the arguments they need: no arguments, the matcheduri only, uri plus extracted params, or uri, params, and ctx. The implementation inspects callback.length (the function arity) to decide which signature applies, so declare exactly the parameters you use. The generic TParams (default Record<string, any>) types the extracted URI parameters and is narrowed automatically when the template definition supplies a Zod schema; HasOAuth controls ctx.auth availability.
Parameters
ReturnsThe matched resource URI (omit in the zero-argument form).Parameters parsed from the URI template placeholders.Request context withreq,client, and optionalauth.
SignatureThe resource content.