aws-iac-mcp-server: search_cdk_documentation raises KeyError 'url' when a result item omits the url field
Describe the bug
Every call to the search_cdk_documentation tool (aws-iac-mcp-server) fails with a bare KeyError: 'url', surfaced to the MCP client as:
Error calling tool 'search_cdk_documentation': 'url'The search-result parser in aws_knowledge_client.py subscripts each result item directly (item['url'], plus item['rank_order'], item['title'], item['context']). When the AWS Knowledge search backend returns a result item that does not include a url key, the whole call raises KeyError('url') and returns no documentation at all — including the items that were well-formed. The tool wrapper does not catch the exception, so the raw KeyError propagates and its string form ("'url'") becomes the client-facing error message.
Reproduces on 1.0.20 and 1.0.21 (latest). The affected code is byte-identical across at least 1.0.10 → 1.0.21, so the trigger is the backend response shape, not a code change in any release.
Expected Behavior
search_cdk_documentation should return the documentation excerpts for the query. Result items missing an optional field such as url should be handled gracefully (default/empty value, or the field treated as optional) so that a single incomplete item does not discard the entire result set.
Current Behavior
The tool returns isError=True with content Error calling tool 'search_cdk_documentation': 'url' for queries whose backend response contains any item without a url key. No results are returned — one malformed item aborts the whole call. Observed 100% failure across multiple queries against the live backend.
Reproduction Steps
- Install the server:
uvx awslabs.aws-iac-mcp-server==1.0.20(also reproduces on==1.0.21). - Launch it as a stdio MCP server and initialize an MCP client session.
- Call the
search_cdk_documentationtool with any of these queries:aws-s3.Bucket encryptionaws-cdk-lib constructDynamoDB table streams
- Each call returns
isError=True, content:Error calling tool 'search_cdk_documentation': 'url'.
The traceback terminates in awslabs/aws_iac_mcp_server/client/aws_knowledge_client.py, in _parse_search_documentation_result, at the url=item['url'] line inside the list comprehension (~line 83).
Deterministic unit-level repro: call _parse_search_documentation_result with a CallToolResult whose content[0].text is JSON of the form {"content": {"result": [{"rank_order": 1, "title": "x", "context": "y"}]}} (no url key) — it raises KeyError('url').
Possible Solution
Parse defensively so a missing optional field degrades gracefully instead of aborting the entire result set:
results = [
KnowledgeResult(
rank=item.get('rank_order', 0),
title=item.get('title', ''),
url=item.get('url', ''), # or make url Optional[str] = None on the dataclass
context=item.get('context', ''),
)
for item in raw_results
]and/or relax the model in knowledge_models.py:
@dataclass
class KnowledgeResult:
rank: int
title: str
context: str
url: Optional[str] = NoneWhether you default the value or skip the item, a single incomplete item should not zero out the whole response — return the well-formed items.
Additional Information/Context
Relevant source (unchanged 1.0.10 → 1.0.21):
awslabs/aws_iac_mcp_server/client/aws_knowledge_client.py
def _parse_search_documentation_result(result: CallToolResult) -> List[KnowledgeResult]:
...
result_content_json = json.loads(content.text)
raw_results = result_content_json['content']['result']
results = [
KnowledgeResult(
rank=item['rank_order'],
title=item['title'],
url=item['url'], # KeyError: 'url'
context=item['context'],
)
for item in raw_results
]
return resultsawslabs/aws_iac_mcp_server/knowledge_models.py
@dataclass
class KnowledgeResult:
rank: int
title: str
url: str
context: strImpact: search_cdk_documentation is currently unusable, so CDK-authoring assistants that depend on it get zero documentation. The other tools served by aws-iac-mcp-server are unaffected.
OS
MacOS
Server
aws-iac-mcp-server
Server Version
1.0.20 and 1.0.21
Region experiencing the issue
us-east-1
Other information
- Server / version:
awslabs.aws-iac-mcp-server1.0.20 and 1.0.21 (installed via uvx) - Python: 3.11
- Transport: stdio, invoked as an MCP server from an agent runtime
- The other aws-iac-mcp-server tools (
validate_cloudformation_template,troubleshoot_cloudformation_deployment,search_cloudformation_documentation, etc.) load and run normally — the failure is isolated to thesearch_cdk_documentation→aws_knowledge_clientresult-parsing path.
Service quota
- I have reviewed the service quotas for this construct
Source: awslabs/mcp