Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Feat/support mcp resources#1042

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
amri369 wants to merge57 commits intoopenai:main
base:main
Choose a base branch
Loading
fromamri369:feat/support-mcp-resources

Conversation

amri369
Copy link
Contributor

@amri369amri369 commentedJul 8, 2025
edited
Loading

Summary

Integrate MCP Resources. This allows MCP servers to expose data and content that can be read by clients and used as context for LLM interactions.

Key changes:

  • Added three abstract methods to the to the base classMCPServer:list_resources,list_resource_templates andread_resource
  • Implemented the abstract methods in the base class_MCPServerWithClientSession which is parent of classesMCPServerStdio,MCPServerSse , andMCPServerStreamableHttp.
  • Created example MCP resources server with working demonstration.
  • Updated documentation with MCP resources usage examples.

Note: This PR does not implementsubscribe_resource andunsubscribe_resource methods.

Test plan

Unit tests: Added 4 comprehensive tests in tests/mcp/test_resources_server.py covering:

  • Resources listing and retrieval
  • Error handling for missing resource
  • Integration tests: Updated existing MCP test suite to handle new abstract methods

Additionally, unit testtest_handoff_prompt_is_correct has been added to increase coverage.

Example verification: Created working example with MCP resources server and client
All tests pass: 527/527 tests passing after adding optional dependencies

Issue number

Partially addresses#544 (resources only)

Checks

  • I've added new tests (if relevant)
  • I've added/updated the relevant documentation
  • I've run make lint and make format
  • I've made sure tests pass

@amri369amri369 marked this pull request as draftJuly 8, 2025 19:43
@amri369amri369 marked this pull request as ready for reviewJuly 8, 2025 22:51
@seratchseratch added enhancementNew feature or request feature:mcp labelsJul 10, 2025
@seratchseratch self-assigned thisJul 10, 2025
@seratch
Copy link
Member

Thanks for sending this PR! Will check it later this week.

@artificial-aidan
Copy link

Does this actually do anything to integrate MCP resources into the agent flow? Or is it up to the implementer to retrieve resources. Seems not very useful?

Tool calls can return links to resources, it seems like it would be more useful to parse tool outputs and use the resource link to return a resource to the LLM.

https://modelcontextprotocol.io/specification/2025-06-18/server/tools#resource-links

@amri369amri369 marked this pull request as draftJuly 12, 2025 06:27
@amri369amri369 marked this pull request as ready for reviewJuly 12, 2025 06:47
@amri369
Copy link
ContributorAuthor

amri369 commentedJul 12, 2025
edited
Loading

Does this actually do anything to integrate MCP resources into the agent flow? Or is it up to the implementer to retrieve resources. Seems not very useful?

Tool calls can return links to resources, it seems like it would be more useful to parse tool outputs and use the resource link to return a resource to the LLM.

https://modelcontextprotocol.io/specification/2025-06-18/server/tools#resource-links

Hey, thanks for the question!
All of the MCP-Resource helper methods live in_MCPServerWithClientSession, so any subclass that inherits from it—MCPServerStdio,MCPServerSse, orMCPServerStreamableHttp—already gets full access in run time to:

  • list_resources
  • list_resource_templates
  • read_resource

@artificial-aidan
Copy link

Does anyone know if openai plans to support resource helper methods in open ai model calls? I experimented with something like this, which findsResourceLinks in tool results and embeds the resource in the response instead

class MCPServerWithResourceLink(MCPServerStreamableHttp):    def __init__(self, *args, **kwargs):        super().__init__(*args, **kwargs)    async def call_tool(self, tool_name: str, arguments: dict[str, t.Any] | None) -> CallToolResult:        result = await super().call_tool(tool_name, arguments)        new_contents = []        for content in result.content:            match content:                case ResourceLink(                    uri=uri,                    annotations=annotations,                ):                    # Retrieve the resource and return it as an embedded resource                    resource_result = await self.read_resource(uri)                    for content in resource_result.contents:                        new_contents.append(                            EmbeddedResource(annotations=annotations, resource=content, type='resource')                        )                case _:                    new_contents.append(content)        return CallToolResult(            content=new_contents,            structuredContent=result.structuredContent,            isError=result.isError,        )

@seratch
Copy link
Member

@artificial-aidan This is a fair question. At the moment, this SDK's agent mechanism does not have plans to directly utilize resources. The proposed resource support here is simply to add methods for using resources within the same code base, but it does not mean your agents can leverage them without additional code from your side.

@amri369
Copy link
ContributorAuthor

Hi@seratch. Did you have the chance to review this PR?
Appreciate any feedback to improve.

@seratch
Copy link
Member

Thanks for the reminder. As I mentioned above, this SDK does not yet have clear use cases with MCP resources, so I have to say that spending my time on this contribution is not a top priority in my task list. I’d appreciate it if you could be a bit patient until we can get back to this 🙇

amri369 reacted with thumbs up emoji

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees

@seratchseratch

Labels
enhancementNew feature or requestfeature:mcp
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@amri369@seratch@artificial-aidan

[8]ページ先頭

©2009-2025 Movatter.jp