Skip to content

Commit 574e4c9

Browse files
kumvpratvishaalmehrishikdbrogan
authored
feat: changed read doc tool to reflect it's generic purpose (#1860)
* feat: changed read doc tool to reflect it's generic purpose * feat: changed read doc tool to reflect it's generic purpose=> cdk_tools turn to iac_tools * feat: changed read doc tool to reflect it's generic purpose=> cdk_tools turn to iac_tools * chore: update src/aws-iac-mcp-server/awslabs/aws_iac_mcp_server/server.py Co-authored-by: Vishaal Mehrishi <[email protected]> * feat: changed read doc tool When To Use section * feat: update tool names in mcp server instructions * chore(aws-iac-mcp-server): update read documentation tool description * Update src/aws-iac-mcp-server/awslabs/aws_iac_mcp_server/server.py * Update src/aws-iac-mcp-server/README.md Co-authored-by: kdbrogan <[email protected]> * feat: update fastmcp dependency and tool description changes for search tools to explain the rank field to LLm --------- Co-authored-by: Vishaal Mehrishi <[email protected]> Co-authored-by: kdbrogan <[email protected]>
1 parent e0063f3 commit 574e4c9

File tree

11 files changed

+68
-68
lines changed

11 files changed

+68
-68
lines changed

.secrets.baseline

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@
133133
"filename": "src/aws-iac-mcp-server/README.md",
134134
"hashed_secret": "df99ad98cabfe1616640820bcfb345ef5b10077f",
135135
"is_verified": false,
136-
"line_number": 290,
136+
"line_number": 306,
137137
"is_secret": false
138138
}
139139
],
@@ -906,5 +906,5 @@
906906
}
907907
]
908908
},
909-
"generated_at": "2025-11-26T15:26:15Z"
909+
"generated_at": "2025-12-01T14:26:01Z"
910910
}

src/aws-iac-mcp-server/README.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,20 @@ Get started with this MCP server for creating and troubleshooting AWS infrastruc
4747

4848
## Available MCP Tools
4949

50+
### Read Documentation Tool
51+
52+
#### read_iac_documentation_page
53+
Fetches and converts any Infrastructure as Code (CDK or CloudFormation) documentation page to markdown format.
54+
55+
**Use this tool to:**
56+
- Read complete CDK documentation pages rather than just excerpts
57+
- Read complete CloudFormation resource type documentation and property references
58+
- Get detailed CloudFormation template syntax and examples
59+
- Access CloudFormation API reference documentation
60+
- Read CloudFormation hooks and lifecycle management guides
61+
- Review CFN Guard policy validation rules and syntax
62+
- Access CloudFormation CLI documentation and usage patterns
63+
5064
### CloudFormation Tools
5165

5266
#### validate_cloudformation_template
@@ -119,8 +133,6 @@ Searches AWS CDK documentation knowledge bases and returns relevant excerpts.
119133
- Use boolean operators: "DynamoDB AND table", "Lambda OR Function"
120134
- Search for specific properties: "bucket encryption", "lambda environment variables"
121135

122-
#### read_cdk_documentation_page
123-
Fetches and converts an AWS CDK documentation page to markdown format.
124136

125137
**Parameters:**
126138
- `url` (required): URL from search results to read the full page content
@@ -180,11 +192,15 @@ Find CDK examples for Lambda function with VPC configuration
180192
Show me CDK constructs for DynamoDB table with encryption
181193
```
182194

183-
#### Read CDK Documentation Page
195+
#### Read Infrastructure as Code Documentation Page
184196
```
185197
Read the full CDK documentation for aws-s3.Bucket from this URL: [URL from search results]
186198
```
187199

200+
```
201+
Read the complete CloudFormation documentation for AWS::S3::Bucket from this URL: [URL from search results]
202+
```
203+
188204
#### Search CDK Samples and Constructs
189205
```
190206
Find CDK code samples for serverless API with TypeScript

src/aws-iac-mcp-server/awslabs/aws_iac_mcp_server/server.py

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@
1616

1717
import json
1818
from .sanitizer import sanitize_tool_response
19-
from .tools.cdk_tools import (
19+
from .tools.cloudformation_compliance_checker import check_compliance, initialize_guard_rules
20+
from .tools.cloudformation_deployment_troubleshooter import DeploymentTroubleshooter
21+
from .tools.cloudformation_pre_deploy_validation import cloudformation_pre_deploy_validation
22+
from .tools.cloudformation_validator import validate_template
23+
from .tools.iac_tools import (
2024
SupportedLanguages,
2125
cdk_best_practices_tool,
22-
read_cdk_documentation_page_tool,
26+
read_iac_documentation_page_tool,
2327
search_cdk_documentation_tool,
2428
search_cdk_samples_and_constructs_tool,
2529
search_cloudformation_documentation_tool,
2630
)
27-
from .tools.cloudformation_compliance_checker import check_compliance, initialize_guard_rules
28-
from .tools.cloudformation_deployment_troubleshooter import DeploymentTroubleshooter
29-
from .tools.cloudformation_pre_deploy_validation import cloudformation_pre_deploy_validation
30-
from .tools.cloudformation_validator import validate_template
3131
from dataclasses import asdict
3232
from mcp.server.fastmcp import FastMCP
3333
from typing import Optional
@@ -49,7 +49,7 @@
4949
- Use `troubleshoot_cloudformation_deployment` when: You need to diagnose CloudFormation deployment failures with root cause analysis and CloudTrail integration
5050
- Use `search_cdk_documentation` when: You need specific CDK construct APIs, properties, or official documentation from AWS CDK knowledge bases
5151
- Use `search_cdk_samples_and_constructs` when: You need working code examples, implementation patterns, or community constructs
52-
- Use `read_cdk_documentation_page` when: You have a specific documentation URL from search results and need complete content with pagination support
52+
- Use `read_iac_documentation_page` when: You have a specific documentation URL from search results and need complete content with pagination support
5353
- Use `search_cloudformation_documentation` when: You need Cloudformation related official documentation, resource type information or template syntax
5454
- Use `cdk_best_practices` when: You need to generate or review CDK code
5555
@@ -308,7 +308,7 @@ async def search_cdk_documentation(query: str) -> str:
308308
Returns JSON with:
309309
- knowledge_response: Details of the response
310310
- results: Array with single result containing:
311-
- rank: Always 1 for document reads
311+
- rank: Search relevance ranking (1 = most relevant, higher is less relevant)
312312
- title: Document title or filename
313313
- url: Source URL of the document
314314
- context: Full or paginated document content
@@ -334,22 +334,19 @@ async def search_cdk_documentation(query: str) -> str:
334334

335335

336336
@mcp.tool()
337-
async def read_cdk_documentation_page(
337+
async def read_iac_documentation_page(
338338
url: str,
339339
starting_index: int = 0,
340340
) -> str:
341-
"""Fetch and convert an AWS CDK documentation page to markdown format.
341+
"""Fetch and convert any Infrastructure as Code (CDK or CloudFormation) documentation page to markdown format.
342342
343343
## Usage
344344
345-
This tool retrieves the complete content of a specific CDK documentation page. Use it when you need detailed information from a particular document rather than the limited context from the search results.
345+
This tool retrieves the complete content of a specific CDK or CloudFormation documentation page. Use it when you need detailed information from a particular document rather than the limited context from the search results.
346346
347347
## When to Use
348348
349-
- Read complete documentation pages rather than just excerpts
350-
- Get the full content of a specific document from search results
351-
- Access detailed API documentation for specific constructs
352-
- Read module READMEs and interface documentation
349+
After using a search tool, use this tool to fetch the complete content of any relevant page in the search results.
353350
354351
## Supported Document Types
355352
@@ -380,7 +377,7 @@ async def read_cdk_documentation_page(
380377
Returns:
381378
List of search results with URLs, titles, and context snippets
382379
"""
383-
result = await read_cdk_documentation_page_tool(url, starting_index)
380+
result = await read_iac_documentation_page_tool(url, starting_index)
384381

385382
# Convert dataclass to dict for JSON serialization
386383
response_dict = asdict(result)
@@ -420,7 +417,7 @@ async def search_cloudformation_documentation(query: str) -> str:
420417
Returns JSON with:
421418
- knowledge_response: Details of the response
422419
- results: Array with single result containing:
423-
- rank: Always 1 for document reads
420+
- rank: Search relevance ranking (1 = most relevant, higher is less relevant)
424421
- title: Document title or filename
425422
- url: Source URL of the document
426423
- context: Full or paginated document content
@@ -488,7 +485,7 @@ async def search_cdk_samples_and_constructs(
488485
Returns JSON with:
489486
- knowledge_response: Details of the response
490487
- results: Array with single result containing:
491-
- rank: Always 1 for document reads
488+
- rank: Search relevance ranking (1 = most relevant, higher is less relevant)
492489
- title: Document title or filename
493490
- url: Source URL of the document
494491
- context: Full or paginated document content

src/aws-iac-mcp-server/awslabs/aws_iac_mcp_server/tools/cdk_tools.py renamed to src/aws-iac-mcp-server/awslabs/aws_iac_mcp_server/tools/iac_tools.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ async def search_cdk_documentation_tool(query: str) -> CDKToolResponse:
4949
)
5050

5151

52-
async def read_cdk_documentation_page_tool(url: str, starting_index: int = 0) -> CDKToolResponse:
53-
"""Read CDK documentation page.
52+
async def read_iac_documentation_page_tool(url: str, starting_index: int = 0) -> CDKToolResponse:
53+
"""Read IaC documentation page.
5454
5555
Args:
5656
url: URL from search results to read the full page content.

src/aws-iac-mcp-server/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ dependencies = [
1212
"botocore>=1.34.0",
1313
"pyyaml>=6.0.0",
1414
"guardpycfn>=0.1.0",
15-
"fastmcp>=0.1.0",
15+
"fastmcp>=2.13.0",
1616
"loguru>=0.7.0",
1717
]
1818
license = {text = "Apache-2.0"}

src/aws-iac-mcp-server/tests/test_server.py

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,15 @@
1616

1717
import json
1818
import pytest
19+
from awslabs.aws_iac_mcp_server.knowledge_models import CDKToolResponse
1920
from awslabs.aws_iac_mcp_server.server import (
2021
cdk_best_practices,
2122
check_cloudformation_template_compliance,
2223
get_cloudformation_pre_deploy_validation_instructions,
24+
read_iac_documentation_page,
25+
search_cdk_documentation,
26+
search_cdk_samples_and_constructs,
27+
search_cloudformation_documentation,
2328
troubleshoot_cloudformation_deployment,
2429
validate_cloudformation_template,
2530
)
@@ -194,9 +199,6 @@ def test_troubleshoot_cloudformation_deployment_non_dict_result(
194199
@pytest.mark.asyncio
195200
async def test_search_cdk_documentation_success(self, mock_sanitize, mock_search):
196201
"""Test successful CDK documentation search."""
197-
from awslabs.aws_iac_mcp_server.knowledge_models import CDKToolResponse
198-
from awslabs.aws_iac_mcp_server.server import search_cdk_documentation
199-
200202
mock_response = CDKToolResponse(
201203
knowledge_response=[],
202204
next_step_guidance='To read the full documentation pages for these search results, use the `read_cdk_documentation_page` tool. If you need to find real code examples for constructs referenced in the search results, use the `search_cdk_samples_and_constructs` tool.',
@@ -214,43 +216,37 @@ async def test_search_cdk_documentation_success(self, mock_sanitize, mock_search
214216
class TestReadCdkDocumentationPage:
215217
"""Test read_cdk_documentation_page tool."""
216218

217-
@patch('awslabs.aws_iac_mcp_server.server.read_cdk_documentation_page_tool')
219+
@patch('awslabs.aws_iac_mcp_server.server.read_iac_documentation_page_tool')
218220
@patch('awslabs.aws_iac_mcp_server.server.sanitize_tool_response')
219221
@pytest.mark.asyncio
220-
async def test_read_cdk_documentation_page_success(self, mock_sanitize, mock_read):
222+
async def test_read_iac_documentation_page_success(self, mock_sanitize, mock_read):
221223
"""Test successful CDK documentation page read."""
222-
from awslabs.aws_iac_mcp_server.knowledge_models import CDKToolResponse
223-
from awslabs.aws_iac_mcp_server.server import read_cdk_documentation_page
224-
225224
mock_response = CDKToolResponse(
226225
knowledge_response=[],
227226
next_step_guidance='If you need code examples, use `search_cdk_samples_and_constructs` tool.',
228227
)
229228
mock_read.return_value = mock_response
230229
mock_sanitize.return_value = 'sanitized response'
231230

232-
result = await read_cdk_documentation_page('https://example.com/doc')
231+
result = await read_iac_documentation_page('https://example.com/doc')
233232

234233
assert result == 'sanitized response'
235234
mock_read.assert_called_once_with('https://example.com/doc', 0)
236235
mock_sanitize.assert_called_once()
237236

238-
@patch('awslabs.aws_iac_mcp_server.server.read_cdk_documentation_page_tool')
237+
@patch('awslabs.aws_iac_mcp_server.server.read_iac_documentation_page_tool')
239238
@patch('awslabs.aws_iac_mcp_server.server.sanitize_tool_response')
240239
@pytest.mark.asyncio
241-
async def test_read_cdk_documentation_page_with_starting_index(self, mock_sanitize, mock_read):
240+
async def test_read_iac_documentation_page_with_starting_index(self, mock_sanitize, mock_read):
242241
"""Test CDK documentation page read with starting index."""
243-
from awslabs.aws_iac_mcp_server.knowledge_models import CDKToolResponse
244-
from awslabs.aws_iac_mcp_server.server import read_cdk_documentation_page
245-
246242
mock_response = CDKToolResponse(
247243
knowledge_response=[],
248244
next_step_guidance='If you need code examples, use `search_cdk_samples_and_constructs` tool.',
249245
)
250246
mock_read.return_value = mock_response
251247
mock_sanitize.return_value = 'sanitized response'
252248

253-
await read_cdk_documentation_page('https://example.com/doc', starting_index=100)
249+
await read_iac_documentation_page('https://example.com/doc', starting_index=100)
254250

255251
mock_read.assert_called_once_with('https://example.com/doc', 100)
256252

@@ -263,9 +259,6 @@ class TestSearchCloudFormationDocumentation:
263259
@pytest.mark.asyncio
264260
async def test_search_cloudformation_documentation_success(self, mock_sanitize, mock_search):
265261
"""Test successful CloudFormation documentation search."""
266-
from awslabs.aws_iac_mcp_server.knowledge_models import CDKToolResponse
267-
from awslabs.aws_iac_mcp_server.server import search_cloudformation_documentation
268-
269262
mock_response = CDKToolResponse(knowledge_response=[], next_step_guidance=None)
270263
mock_search.return_value = mock_response
271264
mock_sanitize.return_value = 'sanitized response'
@@ -285,9 +278,6 @@ class TestSearchCdkSamplesAndConstructs:
285278
@pytest.mark.asyncio
286279
async def test_search_cdk_samples_and_constructs_success(self, mock_sanitize, mock_search):
287280
"""Test successful CDK samples and constructs search."""
288-
from awslabs.aws_iac_mcp_server.knowledge_models import CDKToolResponse
289-
from awslabs.aws_iac_mcp_server.server import search_cdk_samples_and_constructs
290-
291281
mock_response = CDKToolResponse(
292282
knowledge_response=[],
293283
next_step_guidance='To read the full documentation pages for these search results, use the `read_cdk_documentation_page` tool.',
@@ -308,9 +298,6 @@ async def test_search_cdk_samples_and_constructs_with_language(
308298
self, mock_sanitize, mock_search
309299
):
310300
"""Test CDK samples search with specific language."""
311-
from awslabs.aws_iac_mcp_server.knowledge_models import CDKToolResponse
312-
from awslabs.aws_iac_mcp_server.server import search_cdk_samples_and_constructs
313-
314301
mock_response = CDKToolResponse(
315302
knowledge_response=[],
316303
next_step_guidance='To read the full documentation pages for these search results, use the `read_cdk_documentation_page` tool.',

src/aws-iac-mcp-server/tests/tools/test_cdk_search_documentation_tool.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import pytest
1818
from awslabs.aws_iac_mcp_server.knowledge_models import KnowledgeResult
19-
from awslabs.aws_iac_mcp_server.tools.cdk_tools import search_cdk_documentation_tool
19+
from awslabs.aws_iac_mcp_server.tools.iac_tools import search_cdk_documentation_tool
2020
from unittest.mock import AsyncMock, patch
2121

2222

@@ -35,7 +35,7 @@ async def test_search_cdk_documentation_success(self):
3535
)
3636
]
3737
with patch(
38-
'awslabs.aws_iac_mcp_server.tools.cdk_tools.search_documentation',
38+
'awslabs.aws_iac_mcp_server.tools.iac_tools.search_documentation',
3939
new_callable=AsyncMock,
4040
) as mock_search:
4141
mock_search.return_value = mock_response
@@ -53,7 +53,7 @@ async def test_search_cdk_documentation_success(self):
5353
async def test_search_cdk_documentation_error(self):
5454
"""Test CDK documentation search with error handling."""
5555
with patch(
56-
'awslabs.aws_iac_mcp_server.tools.cdk_tools.search_documentation',
56+
'awslabs.aws_iac_mcp_server.tools.iac_tools.search_documentation',
5757
new_callable=AsyncMock,
5858
) as mock_search:
5959
mock_search.side_effect = Exception('Network error')

src/aws-iac-mcp-server/tests/tools/test_read_cdk_documentation_page_tool.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import pytest
1818
from awslabs.aws_iac_mcp_server.knowledge_models import KnowledgeResult
19-
from awslabs.aws_iac_mcp_server.tools.cdk_tools import read_cdk_documentation_page_tool
19+
from awslabs.aws_iac_mcp_server.tools.iac_tools import read_iac_documentation_page_tool
2020
from unittest.mock import AsyncMock, patch
2121

2222

@@ -35,12 +35,12 @@ async def test_read_cdk_documentation_page_success(self):
3535
)
3636
]
3737
with patch(
38-
'awslabs.aws_iac_mcp_server.tools.cdk_tools.read_documentation',
38+
'awslabs.aws_iac_mcp_server.tools.iac_tools.read_documentation',
3939
new_callable=AsyncMock,
4040
) as mock_read:
4141
mock_read.return_value = mock_response
4242

43-
result = await read_cdk_documentation_page_tool(
43+
result = await read_iac_documentation_page_tool(
4444
'https://docs.aws.amazon.com/cdk/test.html'
4545
)
4646

@@ -55,12 +55,12 @@ async def test_read_cdk_documentation_page_success(self):
5555
async def test_read_cdk_documentation_page_with_start_index(self):
5656
"""Test CDK documentation page read with start index."""
5757
with patch(
58-
'awslabs.aws_iac_mcp_server.tools.cdk_tools.read_documentation',
58+
'awslabs.aws_iac_mcp_server.tools.iac_tools.read_documentation',
5959
new_callable=AsyncMock,
6060
) as mock_read:
6161
mock_read.return_value = []
6262

63-
await read_cdk_documentation_page_tool(
63+
await read_iac_documentation_page_tool(
6464
'https://docs.aws.amazon.com/cdk/test.html', 100
6565
)
6666

@@ -72,10 +72,10 @@ async def test_read_cdk_documentation_page_with_start_index(self):
7272
async def test_read_cdk_documentation_page_error(self):
7373
"""Test CDK documentation page read with error handling."""
7474
with patch(
75-
'awslabs.aws_iac_mcp_server.tools.cdk_tools.read_documentation',
75+
'awslabs.aws_iac_mcp_server.tools.iac_tools.read_documentation',
7676
new_callable=AsyncMock,
7777
) as mock_read:
7878
mock_read.side_effect = Exception('Read failed')
7979

8080
with pytest.raises(Exception, match='Read failed'):
81-
await read_cdk_documentation_page_tool('https://docs.aws.amazon.com/cdk/test.html')
81+
await read_iac_documentation_page_tool('https://docs.aws.amazon.com/cdk/test.html')

0 commit comments

Comments
 (0)