mirror of
https://github.com/dnlbauer/cordra-mcp.git
synced 2026-09-10 13:45:30 +00:00
feat: add mcp resource for getting a schema definition
This commit is contained in:
@@ -148,4 +148,38 @@ class CordraClient:
|
||||
return []
|
||||
|
||||
except requests.RequestException as e:
|
||||
raise CordraClientError(f"Failed to search with query '{query}': {e}") from e
|
||||
raise CordraClientError(f"Failed to search with query '{query}': {e}") from e
|
||||
|
||||
async def get_schema(self, schema_name: str) -> DigitalObject:
|
||||
"""Retrieve a schema definition by its name.
|
||||
|
||||
Args:
|
||||
schema_name: The name of the schema to retrieve
|
||||
|
||||
Returns:
|
||||
The schema object containing the type definition
|
||||
|
||||
Raises:
|
||||
CordraNotFoundError: If the schema is not found
|
||||
CordraAuthenticationError: If authentication fails
|
||||
CordraClientError: For other API errors
|
||||
"""
|
||||
# Search for the specific schema by name using correct query format
|
||||
query = f"type:Schema AND /name:{schema_name}"
|
||||
|
||||
try:
|
||||
schemas = await self.find(query)
|
||||
|
||||
if not schemas:
|
||||
raise CordraNotFoundError(f"Schema '{schema_name}' not found")
|
||||
|
||||
# Get the first matching schema (should be unique by name)
|
||||
schema_data = schemas[0]
|
||||
|
||||
# Get the full schema object using its ID
|
||||
return await self.get_object(schema_data['id'])
|
||||
|
||||
except (CordraNotFoundError, CordraAuthenticationError):
|
||||
raise
|
||||
except Exception as e:
|
||||
raise CordraClientError(f"Failed to retrieve schema '{schema_name}': {e}") from e
|
||||
@@ -83,6 +83,32 @@ async def list_cordra_schemas() -> str:
|
||||
raise RuntimeError(f"Failed to list schemas: {e}") from e
|
||||
|
||||
|
||||
@mcp.resource("cordra://schemas/{schema_name}", name="cordra-schema", description="Retrieve a specific Cordra schema definition by name")
|
||||
async def get_cordra_schema(schema_name: str) -> str:
|
||||
"""Retrieve a Cordra schema definition by its name.
|
||||
|
||||
Args:
|
||||
schema_name: The name of the schema to retrieve (e.g., 'Person', 'Document')
|
||||
|
||||
Returns:
|
||||
JSON representation of the schema definition
|
||||
|
||||
Raises:
|
||||
RuntimeError: If the schema is not found or there's an API error
|
||||
"""
|
||||
try:
|
||||
schema_object = await cordra_client.get_schema(schema_name)
|
||||
schema_dict = schema_object.model_dump()
|
||||
return json.dumps(schema_dict, indent=2)
|
||||
|
||||
except CordraNotFoundError:
|
||||
raise RuntimeError(f"Schema not found: {schema_name}")
|
||||
except CordraAuthenticationError as e:
|
||||
raise RuntimeError(f"Authentication failed: {e}") from e
|
||||
except CordraClientError as e:
|
||||
raise RuntimeError(f"Failed to retrieve schema {schema_name}: {e}") from e
|
||||
|
||||
|
||||
@mcp.tool()
|
||||
async def ping() -> str:
|
||||
"""Simple ping tool to test server connectivity."""
|
||||
|
||||
Reference in New Issue
Block a user