get-unified-diff
Extract differences between two text inputs and generate a Unified diff format output. Compare article variations or textual changes efficiently.
Instructions
Get the difference between two text articles in Unified diff format. Use this when you want to extract the difference between texts.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| string_a | Yes | ||
| string_b | Yes |
Input Schema (JSON Schema)
{
"properties": {
"string_a": {
"type": "string"
},
"string_b": {
"type": "string"
}
},
"required": [
"string_a",
"string_b"
],
"type": "object"
}
Implementation Reference
- The @server.call_tool() handler that executes the get-unified-diff tool by generating a unified diff between two input strings using difflib.unified_diff.@server.call_tool() async def handle_call_tool( name: str, arguments: dict | None ) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]: """ Handle tool execution requests. Tools can modify server state and notify clients of changes. """ if name != "get-unified-diff": raise ValueError(f"Unknown tool: {name}") if not arguments: raise ValueError("Missing arguments") string_a: str = arguments.get("string_a") string_b: str = arguments.get("string_b") if string_a is None or string_b is None: raise ValueError("Missing 'string_a' or 'string_b' in arguments") diff_iterator = difflib.unified_diff(string_a.splitlines(), string_b.splitlines()) return [types.TextContent(type="text", text="\n".join(diff_iterator))]
- JSON schema defining the required input parameters 'string_a' and 'string_b' for the get-unified-diff tool.inputSchema={ "type": "object", "properties": { "string_a": {"type": "string"}, "string_b": {"type": "string"}, }, "required": ["string_a", "string_b"], },
- src/mcp_server_diff_python/server.py:11-30 (registration)@server.list_tools() decorator registers the get-unified-diff tool including its name, description, and input schema.@server.list_tools() async def handle_list_tools() -> list[types.Tool]: """ List available tools. Each tool specifies its arguments using JSON Schema validation. """ return [ types.Tool( name="get-unified-diff", description="Get the difference between two text articles in Unified diff format. Use this when you want to extract the difference between texts.", # noqa: E501 inputSchema={ "type": "object", "properties": { "string_a": {"type": "string"}, "string_b": {"type": "string"}, }, "required": ["string_a", "string_b"], }, ) ]