Skip to content
This repository was archived by the owner on May 29, 2026. It is now read-only.

Commit 92a37da

Browse files
authored
Add missing resolveResource method to ResourceHost interface and update MCP documentation (#1879)
1 parent 4b46d0f commit 92a37da

3 files changed

Lines changed: 76 additions & 1 deletion

File tree

docs/src/content/docs/blog/mcp-resources.mdx

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,11 @@ graph TD
8383
MCP handles discovery and resolution of resources, so once your script publishes a resource,
8484
the MCP client (IDE) is made "aware" of it and it can decide to read it.
8585

86-
## `publishResource`
86+
## ResourceHost Methods
87+
88+
The ResourceHost interface provides several methods for working with MCP resources:
89+
90+
### `publishResource`
8791

8892
The `publishResource` method allows you to publish a resource with a unique identifier and a file/string/buffer.
8993
The rest of the MCP resource publishing process is handled by the GenAIScript framework.
@@ -92,6 +96,61 @@ The rest of the MCP resource publishing process is handled by the GenAIScript fr
9296
const uri = await host.publishResource("unique-id", file);
9397
```
9498

99+
You can also provide additional options like description and MIME type:
100+
101+
```js
102+
const uri = await host.publishResource("my-data", content, {
103+
description: "A sample data file",
104+
mimeType: "application/json"
105+
});
106+
```
107+
108+
### `resources`
109+
110+
The `resources` method returns a list of all available resource references that have been published.
111+
112+
```js
113+
const resourceRefs = await host.resources();
114+
for (const ref of resourceRefs) {
115+
console.log(`Resource: ${ref.name} (${ref.uri})`);
116+
if (ref.description) console.log(` Description: ${ref.description}`);
117+
if (ref.mimeType) console.log(` Type: ${ref.mimeType}`);
118+
}
119+
```
120+
121+
### `resolveResource`
122+
123+
The `resolveResource` method allows you to resolve URLs to retrieve associated files and resources.
124+
It supports various protocols including https, file, git, gist, and vscode.
125+
126+
```js
127+
const result = await host.resolveResource("https://raw.githubusercontent.com/user/repo/main/README.md");
128+
if (result) {
129+
console.log(`Resolved URL: ${result.uri}`);
130+
for (const file of result.files) {
131+
console.log(`File: ${file.filename}`);
132+
// Access file.content for the actual content
133+
}
134+
}
135+
```
136+
137+
Supported URL patterns include:
138+
139+
- **HTTPS URLs**: Direct file downloads from web servers
140+
- **GitHub blob URLs**: Automatically converted to raw content URLs
141+
- **GitHub asset URLs**: Resolved through GitHub API
142+
- **Gist URLs**: Access to GitHub gists (e.g., `https://gist.github.com/user/gistid`)
143+
- **Git repositories**: Clone and access files (e.g., `https://github.com/user/repo.git`)
144+
- **VSCode URLs**: gistfs extension URLs for accessing gists
145+
146+
```js
147+
// Examples of supported URL patterns
148+
await host.resolveResource("https://github.com/user/repo/blob/main/file.txt");
149+
await host.resolveResource("gist://abc123def456/myfile.js");
150+
await host.resolveResource("https://github.com/user/repo.git/path/to/file");
151+
await host.resolveResource("vscode://vsls-contrib.gistfs/open?gist=123&file=script.js");
152+
```
153+
95154
## Next steps
96155

97156
Are you ready to build your own MCP tools and resources?

docs/src/content/docs/guides/genaiscript.d.ts

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

genaiscript.d.ts

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)