|
| 1 | +"""Integration tests for MCP tools accepting string-serialized list/dict params. |
| 2 | +
|
| 3 | +Goes through the full FastMCP Client → validate_call → tool function path, |
| 4 | +which is where Pydantic rejects strings for list/dict params. |
| 5 | +""" |
| 6 | + |
| 7 | +import pytest |
| 8 | +from fastmcp import Client |
| 9 | + |
| 10 | + |
| 11 | +@pytest.mark.asyncio |
| 12 | +async def test_search_notes_entity_types_as_string(mcp_server, app, test_project): |
| 13 | + """search_notes should accept entity_types as a JSON string via MCP protocol.""" |
| 14 | + async with Client(mcp_server) as client: |
| 15 | + await client.call_tool( |
| 16 | + "write_note", |
| 17 | + { |
| 18 | + "project": test_project.name, |
| 19 | + "title": "Entity Type Coerce Test", |
| 20 | + "directory": "test", |
| 21 | + "content": "# Test\nContent for entity type coercion", |
| 22 | + }, |
| 23 | + ) |
| 24 | + |
| 25 | + # MCP client sends entity_types as a string |
| 26 | + result = await client.call_tool( |
| 27 | + "search_notes", |
| 28 | + { |
| 29 | + "project": test_project.name, |
| 30 | + "query": "coercion", |
| 31 | + "entity_types": '["entity"]', |
| 32 | + }, |
| 33 | + ) |
| 34 | + text = result.content[0].text |
| 35 | + assert "Search Failed" not in text |
| 36 | + |
| 37 | + |
| 38 | +@pytest.mark.asyncio |
| 39 | +async def test_search_notes_note_types_as_string(mcp_server, app, test_project): |
| 40 | + """search_notes should accept note_types as a JSON string via MCP protocol.""" |
| 41 | + async with Client(mcp_server) as client: |
| 42 | + await client.call_tool( |
| 43 | + "write_note", |
| 44 | + { |
| 45 | + "project": test_project.name, |
| 46 | + "title": "Note Type Coerce Test", |
| 47 | + "directory": "test", |
| 48 | + "content": "# Test\nContent for note type coercion", |
| 49 | + }, |
| 50 | + ) |
| 51 | + |
| 52 | + result = await client.call_tool( |
| 53 | + "search_notes", |
| 54 | + { |
| 55 | + "project": test_project.name, |
| 56 | + "query": "coercion", |
| 57 | + "note_types": '["note"]', |
| 58 | + }, |
| 59 | + ) |
| 60 | + text = result.content[0].text |
| 61 | + assert "Search Failed" not in text |
| 62 | + |
| 63 | + |
| 64 | +@pytest.mark.asyncio |
| 65 | +async def test_search_notes_tags_as_string(mcp_server, app, test_project): |
| 66 | + """search_notes should accept tags as a JSON string via MCP protocol.""" |
| 67 | + async with Client(mcp_server) as client: |
| 68 | + await client.call_tool( |
| 69 | + "write_note", |
| 70 | + { |
| 71 | + "project": test_project.name, |
| 72 | + "title": "Tags Coerce Test", |
| 73 | + "directory": "test", |
| 74 | + "content": "# Test\nTagged content for coercion", |
| 75 | + "tags": "alpha", |
| 76 | + }, |
| 77 | + ) |
| 78 | + |
| 79 | + result = await client.call_tool( |
| 80 | + "search_notes", |
| 81 | + { |
| 82 | + "project": test_project.name, |
| 83 | + "query": "tagged", |
| 84 | + "tags": '["alpha"]', |
| 85 | + }, |
| 86 | + ) |
| 87 | + text = result.content[0].text |
| 88 | + assert "Search Failed" not in text |
| 89 | + |
| 90 | + |
| 91 | +@pytest.mark.asyncio |
| 92 | +async def test_search_notes_metadata_filters_as_string(mcp_server, app, test_project): |
| 93 | + """search_notes should accept metadata_filters as a JSON string via MCP protocol.""" |
| 94 | + async with Client(mcp_server) as client: |
| 95 | + await client.call_tool( |
| 96 | + "write_note", |
| 97 | + { |
| 98 | + "project": test_project.name, |
| 99 | + "title": "Metadata Coerce Test", |
| 100 | + "directory": "test", |
| 101 | + "content": "# Test\nMetadata content for coercion", |
| 102 | + }, |
| 103 | + ) |
| 104 | + |
| 105 | + result = await client.call_tool( |
| 106 | + "search_notes", |
| 107 | + { |
| 108 | + "project": test_project.name, |
| 109 | + "query": "metadata", |
| 110 | + "metadata_filters": '{"type": "note"}', |
| 111 | + }, |
| 112 | + ) |
| 113 | + text = result.content[0].text |
| 114 | + assert "Search Failed" not in text |
| 115 | + |
| 116 | + |
| 117 | +@pytest.mark.asyncio |
| 118 | +async def test_write_note_metadata_as_string(mcp_server, app, test_project): |
| 119 | + """write_note should accept metadata as a JSON string via MCP protocol.""" |
| 120 | + async with Client(mcp_server) as client: |
| 121 | + result = await client.call_tool( |
| 122 | + "write_note", |
| 123 | + { |
| 124 | + "project": test_project.name, |
| 125 | + "title": "String Metadata Note", |
| 126 | + "directory": "test", |
| 127 | + "content": "# Test\nWith string metadata", |
| 128 | + "metadata": '{"priority": "high"}', |
| 129 | + }, |
| 130 | + ) |
| 131 | + text = result.content[0].text |
| 132 | + assert "Created note" in text or "Updated note" in text |
| 133 | + |
| 134 | + |
| 135 | +@pytest.mark.asyncio |
| 136 | +async def test_canvas_nodes_edges_as_string(mcp_server, app, test_project): |
| 137 | + """canvas should accept nodes and edges as JSON strings via MCP protocol.""" |
| 138 | + import json |
| 139 | + |
| 140 | + nodes = [ |
| 141 | + { |
| 142 | + "id": "n1", |
| 143 | + "type": "text", |
| 144 | + "text": "Hello", |
| 145 | + "x": 0, |
| 146 | + "y": 0, |
| 147 | + "width": 200, |
| 148 | + "height": 100, |
| 149 | + } |
| 150 | + ] |
| 151 | + edges = [ |
| 152 | + {"id": "e1", "fromNode": "n1", "toNode": "n1", "label": "self"} |
| 153 | + ] |
| 154 | + |
| 155 | + async with Client(mcp_server) as client: |
| 156 | + result = await client.call_tool( |
| 157 | + "canvas", |
| 158 | + { |
| 159 | + "project": test_project.name, |
| 160 | + "title": "Coerce Canvas Test", |
| 161 | + "directory": "test", |
| 162 | + "nodes": json.dumps(nodes), |
| 163 | + "edges": json.dumps(edges), |
| 164 | + }, |
| 165 | + ) |
| 166 | + text = result.content[0].text |
| 167 | + assert "Created" in text or "Updated" in text |
0 commit comments