Skip to content

MCP: resource_link response in a tool should automatically include the resource in the context #256487

Closed
@samuelfernandez

Description

@samuelfernandez

Related to #248418

MCP resources are added to the chat as context, based on user's action. In general, it seems that, in contrast with tools, the agent won't include them automatically.

However, if a tool responds with a resource_link, pointing to a resource that hasn't been added to the context, ideally the agent will find it and include it, as it would do with any other code reference in the code base. It could also be mentioned in the chat that it was accessed.

Example from https://github.com/modelcontextprotocol/typescript-sdk?tab=readme-ov-file#tools

// Tool that returns ResourceLinks
server.registerTool(
  "list-files",
  {
    title: "List Files",
    description: "List project files",
    inputSchema: { pattern: z.string() }
  },
  async ({ pattern }) => ({
    content: [
      { type: "text", text: `Found files matching "${pattern}":` },
      // ResourceLinks let tools return references without file content
      {
        type: "resource_link",
        uri: "file:///project/README.md",
        name: "README.md",
        mimeType: "text/markdown",
        description: 'A README file'
      },
      {
        type: "resource_link",
        uri: "file:///project/src/index.ts",
        name: "index.ts",
        mimeType: "text/typescript",
        description: 'An index file'
      }
    ]
  })
);

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions