Skip to content

Commit

Permalink
chore: improve resource listing
Browse files Browse the repository at this point in the history
  • Loading branch information
phil65 committed Nov 29, 2024
1 parent 96e2f1a commit 7231f12
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
20 changes: 15 additions & 5 deletions src/llmling/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,18 +186,28 @@ async def handle_list_resources() -> list[mcp.types.Resource]:
resources = []
for name in self.runtime.list_resources():
try:
resource = await self.runtime.load_resource(name)
# First get URI and basic info without loading
uri = self.runtime.get_resource_uri(name)
resource_config = self.runtime._config.resources[
name
] # Get raw config

mcp_resource = mcp.types.Resource(
uri=conversions.to_mcp_uri(uri),
name=resource.metadata.name or name,
description=resource.metadata.description,
mimeType=resource.metadata.mime_type,
name=name,
description=resource_config.description,
mimeType="text/plain", # Default, could be made more specific
)
resources.append(mcp_resource)

except Exception:
logger.exception("Failed to create resource %r", name)
logger.exception(
"Failed to create resource listing for %r. Config: %r",
name,
self.runtime._config.resources.get(name),
)
continue

return resources

@self.server.read_resource()
Expand Down
2 changes: 1 addition & 1 deletion tests/server/test_mcp_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ async def test_mcp_resource_operations(configured_client: MCPInProcSession) -> N
assert "resources" in response
resource_list = response["resources"]
assert len(resource_list) >= 1
test_resource = next(r for r in resource_list if r["name"] == "Test resource")
test_resource = next(r for r in resource_list if r["description"] == "Test resource")

# Read resource content
response = await configured_client.send_request(
Expand Down

0 comments on commit 7231f12

Please sign in to comment.