Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3.13
- # date: 2025.09.05
- # [python - Why doesn't MCP server expose my resources? - Stack Overflow](https://stackoverflow.com/questions/79756235/why-doesnt-mcp-server-expose-my-resources?noredirect=1#comment140716418_79756235)
- # Doc: [FastMC - Call Your Server](https://gofastmcp.com/getting-started/quickstart#call-your-server)
- # Run:
- # python client.py # run with port 8000
- # python client.py 7000 # run with port 7000
- # Server needs:
- # - FastMCP:
- # from fastmcp import FastMCP
- # mcp.run(transport='http', port=7000)
- # - mcp.server.FastMCP:
- # from mcp.server.fastmcp import FastMCP
- # mcp = FastMCP("Demo", port=7000)
- # mcp.run(transport='streamable-http') # it doesn't allow to set `port` here - port has to be in FastMCP
- import sys
- import asyncio
- from fastmcp import Client
- if len(sys.argv) > 1:
- PORT = int(sys.argv[1])
- else:
- PORT = 8000 # usually I use this port with different server
- client = Client(f"http://localhost:{PORT}/mcp") # doc forgot `/mcp`
- async def main():
- async with client:
- # it doesn't show "dynamic resources" (or rather "resource patterns")
- resources = await client.list_resources()
- print(f'--- resources ({len(resources)}) ---')
- for item in resources:
- print(item)
- tools = await client.list_tools()
- print(f'--- tools ({len(tools)}) ---')
- for item in tools:
- print(item)
- prompts = await client.list_prompts()
- print(f'--- prompts ({len(prompts)}) ---')
- for item in prompts:
- print(item)
- # it can use "dynamic resources" (or rather "resource patterns")
- print('--- reading resources ---')
- result = await client.read_resource('greeting://Adam') # @mcp.resource('greeting://{name}')
- #results = await client.read_resource('greeting:Adam') # @mcp.resource('greeting:{name}')
- print(results)
- for item in results:
- print(item.text)
- #print('--- call tools ---')
- #name = "Adam"
- #result = await client.call_tool("greet", {"name": name})
- #print(result)
- #for item in result.content:
- # print(item.text)
- asyncio.run(main())
Advertisement
Add Comment
Please, Sign In to add comment