We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/huangjien/writer-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server
"""Character management tools for Writer MCP."""
from typing import Any, Dict, List, Optional
from mcp.types import CallToolRequest, Tool, TextContent
from ..database.connection import DatabaseConnection
from ..utils.logger import get_logger
logger = get_logger(__name__)
def get_character_tools() -> List[Tool]:
"""Get list of available character management tools."""
return [
Tool(
name="create_character",
description="Create a new character in the knowledge base",
inputSchema={
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "Character name"
},
"description": {
"type": "string",
"description": "Character description"
},
"tags": {
"type": "array",
"items": {"type": "string"},
"description": "Character tags"
}
},
"required": ["name", "description"]
}
),
Tool(
name="search_characters",
description="Search for characters using semantic or text search",
inputSchema={
"type": "object",
"properties": {
"query": {
"type": "string",
"description": "Search query"
},
"limit": {
"type": "integer",
"description": "Maximum number of results",
"default": 10
}
},
"required": ["query"]
}
),
Tool(
name="add_character_fact",
description="Add a knowledge fact about a character",
inputSchema={
"type": "object",
"properties": {
"character_id": {
"type": "integer",
"description": "Character ID"
},
"fact_type": {
"type": "string",
"description": "Type of fact (appearance, personality, background, etc.)"
},
"content": {
"type": "string",
"description": "Fact content"
}
},
"required": ["character_id", "fact_type", "content"]
}
),
Tool(
name="search_facts",
description="Search for character facts",
inputSchema={
"type": "object",
"properties": {
"query": {
"type": "string",
"description": "Search query"
},
"character_id": {
"type": "integer",
"description": "Optional character ID to filter by"
},
"fact_type": {
"type": "string",
"description": "Optional fact type to filter by"
},
"limit": {
"type": "integer",
"description": "Maximum number of results",
"default": 10
}
},
"required": ["query"]
}
),
Tool(
name="generate_character_tags",
description="Generate tags for a character using AI",
inputSchema={
"type": "object",
"properties": {
"character_id": {
"type": "integer",
"description": "Character ID"
}
},
"required": ["character_id"]
}
),
Tool(
name="analyze_character_relationships",
description="Analyze relationships between characters using AI",
inputSchema={
"type": "object",
"properties": {
"character_ids": {
"type": "array",
"items": {"type": "integer"},
"description": "List of character IDs to analyze"
}
},
"required": ["character_ids"]
}
)
]
async def handle_tool_call(
request: CallToolRequest,
db: Optional[DatabaseConnection]
) -> List[TextContent]:
"""Handle tool calls for character management."""
if not db:
return [TextContent(type="text", text="Database not available")]
try:
if request.name == "create_character":
return await create_character(request.arguments, db)
elif request.name == "search_characters":
return await search_characters(request.arguments, db)
elif request.name == "add_character_fact":
return await add_character_fact(request.arguments, db)
elif request.name == "search_facts":
return await search_facts(request.arguments, db)
elif request.name == "generate_character_tags":
return await generate_character_tags(request.arguments, db)
elif request.name == "analyze_character_relationships":
return await analyze_character_relationships(request.arguments, db)
else:
return [TextContent(type="text", text=f"Unknown tool: {request.name}")]
except Exception as e:
logger.error(f"Error in tool {request.name}: {e}")
return [TextContent(type="text", text=f"Error: {str(e)}")]
async def create_character(
args: Dict[str, Any],
db: DatabaseConnection
) -> List[TextContent]:
"""Create a new character."""
# TODO: Implement character creation
return [TextContent(
type="text",
text="Character creation not yet implemented"
)]
async def search_characters(
args: Dict[str, Any],
db: DatabaseConnection
) -> List[TextContent]:
"""Search for characters."""
# TODO: Implement character search
return [TextContent(
type="text",
text="Character search not yet implemented"
)]
async def add_character_fact(
args: Dict[str, Any],
db: DatabaseConnection
) -> List[TextContent]:
"""Add a fact about a character."""
# TODO: Implement fact addition
return [TextContent(
type="text",
text="Fact addition not yet implemented"
)]
async def search_facts(
args: Dict[str, Any],
db: DatabaseConnection
) -> List[TextContent]:
"""Search for character facts."""
# TODO: Implement fact search
return [TextContent(
type="text",
text="Fact search not yet implemented"
)]
async def generate_character_tags(
args: Dict[str, Any],
db: DatabaseConnection
) -> List[TextContent]:
"""Generate tags for a character using AI."""
# TODO: Implement AI tag generation
return [TextContent(
type="text",
text="Tag generation not yet implemented"
)]
async def analyze_character_relationships(
args: Dict[str, Any],
db: DatabaseConnection
) -> List[TextContent]:
"""Analyze character relationships using AI."""
# TODO: Implement relationship analysis
return [TextContent(
type="text",
text="Relationship analysis not yet implemented"
)]