@@ -83,7 +83,11 @@ graph TD
8383MCP handles discovery and resolution of resources, so once your script publishes a resource,
8484the 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
8892The ` publishResource ` method allows you to publish a resource with a unique identifier and a file/string/buffer.
8993The 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
9296const 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
97156Are you ready to build your own MCP tools and resources?
0 commit comments