interface OwWorldFileEntry { /** Relative to the world's folder, `/`-separated. */ path: string; data: Uint8Array; } /** * `@onlyworlds/sdk/mcp`: the hosted MCP door's read tools, answered on this computer from world folders. * `folderMcpTools(worlds)` gives the tool definitions, resources and templates the door lists, and a * `callTool` and a `readResource` that answer as the door answers, each world read through an * `OwV2Client` on `folderFetch(entries)`. No transport, no MCP library, no file system: a server wraps * it (stdio, a pipe, HTTP), and the same layer answers for a folder on disk, a `.owworld` file's entries * or a browser's folder handle. * * ```ts * import { entriesFromDirectory } from '@onlyworlds/sdk/folder'; * import { folderMcpTools } from '@onlyworlds/sdk/mcp'; * * const mcp = folderMcpTools([{ entries: await entriesFromDirectory('./my-world') }]); * mcp.tools; // as tools/list carries them * await mcp.callTool('list_elements', { type: 'character' }); // a CallToolResult, as the door's * ``` * * The tools are the door's read tools a folder can answer, by the door's names, parameters and * answers: `list_element_types`, `get_element_schema`, `search_schema`, `list_worlds`, `get_me`, * `list_elements`, `count_elements`, `get_element` and `search_elements`; the resources `onlyworlds://schema` and * `onlyworlds://world`, the templates `onlyworlds://schema/{type}` and * `onlyworlds://element/{type}/{id}`. What a folder cannot answer (`get_changes`, `get_draught`, * `list_files`, `read_file`, the writes) is not listed, and a call to it is the door's answer to a * tool it does not have. `world` on a call is the id in the world's `world.json` (as `list_worlds` * lists it); left out, it is the one world served. The definitions and the schema tools' answers were read from the * live door when the package was built (`door.json`, `schemaVersion`), never retyped. * * Every read goes through each world's client, as its owner reads it: the list, the element and the * world; the search is keel's word rule (the folder source's) over the elements the client serves, so * what `include_room` and `include_proposed` leave out is left out before the limit, as the door does. */ /** * What the tools ask of a world's client, all reads: an `OwV2Client` is one, on `folderFetch(entries)` for * a folder. Written as its shape, so a client from the package's main entry fits it. */ interface OwMcpReader { list(type: string, params: { limit?: number; cursor?: string; filter?: Record; ids?: string[]; createdBy?: string; }): Promise<{ data: object[]; has_more: boolean; next_cursor: string | null; }>; get(type: string, id: string): Promise; getWorld(): Promise; } /** * One world the tools serve: its files (`entries`, as `folderFetch` takes them), or a client that reads it. * Its id, name and slug are its own body's (`GET /world`, a folder's `world.json`), read on the first call. */ interface OwMcpWorld { /** The world's files, `{ path, data }` relative to its folder: read through `folderFetch(entries)`. */ entries?: readonly OwWorldFileEntry[]; /** A client that reads the world as its owner: an `OwV2Client` (on `folderFetch` for a folder). Give `entries` or `client`, not both. */ client?: OwMcpReader; } interface OwMcpToolsOptions { /** True: each description exactly as the hosted door serves it, without the sentence saying it answers on this computer. Default false. */ asServed?: boolean; } /** A tool as `tools/list` carries it. */ interface OwMcpTool { name: string; description: string; inputSchema: Record; outputSchema?: Record; annotations: Record; } /** A resource as `resources/list` carries it. */ interface OwMcpResource { name: string; uri: string; description: string; mimeType: string; } /** A resource template as `resources/templates/list` carries it. */ interface OwMcpResourceTemplate { name: string; uriTemplate: string; description: string; mimeType: string; } /** One text content item. */ interface OwMcpTextContent { type: 'text'; text: string; } /** * A tool's answer, shaped as MCP's `CallToolResult` and as the door answers: the JSON as text content * and as `structuredContent`, the same value; a refusal as text alone, with `isError` true. */ interface OwMcpCallToolResult { content: OwMcpTextContent[]; structuredContent?: Record; isError: boolean; } /** A resource read's answer, as MCP's `ReadResourceResult`: the JSON as the door writes it (Python's `json.dumps`). */ interface OwMcpReadResourceResult { contents: { uri: string; mimeType: string; text: string; }[]; } /** The JSON-RPC error code a resource read that names nothing answers with, as the door does. */ declare const MCP_RESOURCE_NOT_FOUND = -32002; /** * A resource read the door answers with a JSON-RPC error: `code` is `MCP_RESOURCE_NOT_FOUND` when the * URI names nothing (an unknown resource, a type that is none, an id that is no UUID or no element), and * 0 for any other refusal, as the door's server sends them. A server answers it as that error. */ declare class OwMcpError extends Error { readonly code: number; constructor(code: number, message: string); } interface OwMcpTools { /** The read tools, as `tools/list` carries them, in the door's order. */ readonly tools: OwMcpTool[]; /** As `resources/list` carries them. */ readonly resources: OwMcpResource[]; /** As `resources/templates/list` carries them. */ readonly resourceTemplates: OwMcpResourceTemplate[]; /** The schema version (X-OW-Schema-Version) the schema tools' vendored answers were read at. */ readonly schemaVersion: string; /** `tools/call`: the tool's answer; a refusal is an answer too (`isError`), never a rejection. */ callTool(name: string, args?: Record | null): Promise; /** `resources/read`: the resource's text, or an `OwMcpError` for the JSON-RPC error the door answers. */ readResource(uri: string): Promise; } /** * The hosted door's read tools over `worlds`, each a world folder's `entries` or a client that reads * it. Nothing is read until the first call; each call reads through the world's client then. With one * world served, a call without `world` reads it; with more, it names one (`list_worlds` lists them). With * none (a server that starts before a folder is added), the schema tools answer, `list_worlds` answers an * empty list, and every read of a world is refused by one sentence. * `opts.asServed` keeps the descriptions exactly as the door serves them. A key it does not know is * refused with a TypeError, as is a world without `entries` or `client`, or with both, and a `worlds` that is no list. */ declare function folderMcpTools(worlds: readonly OwMcpWorld[], opts?: OwMcpToolsOptions): OwMcpTools; export { MCP_RESOURCE_NOT_FOUND, OwMcpError, folderMcpTools }; export type { OwMcpCallToolResult, OwMcpReadResourceResult, OwMcpReader, OwMcpResource, OwMcpResourceTemplate, OwMcpTextContent, OwMcpTool, OwMcpTools, OwMcpToolsOptions, OwMcpWorld, OwWorldFileEntry };