Skip to content

Commit 053c4c4

Browse files
HarikaPonnadaniel-butler-irlHarika-Ponna
authored
feat: Added following features:<br> - uses Terraform Registry API as the primary data source for list-content tool<br> - added Example details tool that retrieves detailed information about specific examples<br> - added documentaiton for the supported tools (#86)
* feat: Add get_module_structure method to TerraformClient for detailed module information retrieval feat: Implement get_example_details tool for fetching and formatting example details from Terraform Registry refactor: Update list_content implementation to prioritize Terraform Registry API for examples and submodules fix: Adjust ContentPath type description to remove solutions category test: Add comprehensive tests for get_example_details tool and its formatting functions * fix: Enhance example retrieval instructions for context efficiency and clarity * docs: Add MCP tools reference documentation for efficient context gathering * fix: Clean up code formatting and improve readability across multiple files * fix: use async context managers and remove dead API call * test: update list_content tests to support async context managers * fix: pre-commit hook failures * fix: apply ruff formatting fixes --------- Co-authored-by: Daniel Butler <dannyeb@gmail.com> Co-authored-by: Harika-Ponna <Harika.Ponna@ibm.com>
1 parent 1ee147c commit 053c4c4

File tree

9 files changed

+1568
-430
lines changed

9 files changed

+1568
-430
lines changed

docs/tools.md

Lines changed: 252 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,252 @@
1+
# MCP Tools Reference
2+
3+
TIM-MCP provides five tools designed for **efficient context gathering**. Each tool retrieves specific information to **minimize token usage** while **maximizing relevance**. The goal is to gather only the context needed for the user's task - no more, no less.
4+
5+
## Context Efficiency Strategy
6+
7+
- **Progressive disclosure**: Start with lightweight tools (`search_modules`, `list_content`) to understand what's available before fetching heavy content
8+
- **Targeted retrieval**: Use filters (`include_files`, `exclude_files`) to fetch only relevant files
9+
- **Smart caching**: Registry metadata (`get_module_details`, `get_example_details`) is faster than fetching source code
10+
- **Choose wisely**: Examples are better than raw module details when available
11+
12+
## Quick Reference
13+
14+
| Tool | Context Weight | Primary Use |
15+
|------|----------------|-------------|
16+
| `search_modules` | Lightweight | Find module IDs (essential first step) |
17+
| `list_content` | Lightweight | Discover what examples/content exist |
18+
| `get_example_details` | Medium | Understand example without fetching code |
19+
| `get_module_details` | Medium | Get module interface for custom builds |
20+
| `get_content` | Heavy | Fetch actual source code (be selective!) |
21+
22+
## search_modules
23+
24+
Find modules in the Terraform Registry based on a search query.
25+
26+
**When to use:**
27+
- User asks "what modules are available for X"
28+
- User wants to find modules related to a specific IBM Cloud service
29+
- Starting point for any module discovery
30+
31+
**Parameters:**
32+
```
33+
query (required): Search term like "vpc", "kubernetes", "observability"
34+
limit (optional): Number of results, default 5
35+
```
36+
37+
**Returns:** JSON with module IDs, descriptions, download counts, and verification status
38+
39+
**Example:**
40+
```
41+
search_modules(query="vpc", limit=5)
42+
```
43+
44+
---
45+
46+
## get_module_details
47+
48+
Get structured module metadata from the Terraform Registry including inputs, outputs, dependencies, and requirements.
49+
50+
**When to use:**
51+
- User wants to **write custom terraform** using a module
52+
- User asks about "what inputs does this need", "what outputs", "what parameters"
53+
- User is **building new configurations** from scratch
54+
55+
**When NOT to use:**
56+
- User wants examples or sample code (use `list_content` + `get_content` instead)
57+
- Examples exist and are more helpful than raw interface details
58+
59+
**Parameters:**
60+
```
61+
module_id (required):
62+
- "terraform-ibm-modules/vpc/ibm" (latest version)
63+
- "terraform-ibm-modules/vpc/ibm/7.19.0" (specific version)
64+
```
65+
66+
**Returns:** Markdown with module description, required/optional inputs with types and defaults, outputs, provider requirements, and dependencies
67+
68+
**Example:**
69+
```
70+
get_module_details(module_id="terraform-ibm-modules/vpc/ibm")
71+
```
72+
73+
---
74+
75+
## list_content
76+
77+
List the repository structure including available examples, submodules, and documentation.
78+
79+
**When to use:**
80+
- User asks for "examples", "sample code", "how to use this module"
81+
- First step before fetching any example code
82+
- User wants to explore what's in the repository
83+
84+
**Parameters:**
85+
```
86+
module_id (required):
87+
- "terraform-ibm-modules/vpc/ibm" (latest version)
88+
- "terraform-ibm-modules/vpc/ibm/7.19.0" (specific version)
89+
```
90+
91+
**Returns:** Markdown organized by category:
92+
- **Examples**: Working deployment examples (most important for users wanting samples)
93+
- **Root Module**: Main module files
94+
- **Submodules**: Reusable components
95+
96+
Each item includes a description to help select the most relevant one.
97+
98+
**Example:**
99+
```
100+
list_content(module_id="terraform-ibm-modules/vpc/ibm")
101+
```
102+
103+
**Tip:** When user wants examples, review the list and select the most appropriate one (e.g., `examples/basic` for simple use cases, `examples/complete` for comprehensive examples).
104+
105+
---
106+
107+
## get_example_details
108+
109+
Get detailed metadata about a specific example from the Terraform Registry **without fetching the full source code**. This is a context-efficient alternative to `get_content` when you need to understand what an example does.
110+
111+
**When to use:**
112+
- After `list_content` shows available examples
113+
- You want to verify an example matches user needs before fetching code (saves tokens!)
114+
- User asks "what does this example need" or "what will this create"
115+
- Multiple examples exist and you need to pick the right one
116+
117+
**Parameters:**
118+
```
119+
module_id (required):
120+
- "terraform-ibm-modules/vpc/ibm" (latest version)
121+
- "terraform-ibm-modules/vpc/ibm/7.19.0" (specific version)
122+
example_path (required): Path from list_content like "examples/basic"
123+
```
124+
125+
**Returns:** Markdown with:
126+
- Example description and README
127+
- Required and optional inputs with types and defaults
128+
- Outputs produced
129+
- Provider and module dependencies
130+
- Resources created
131+
132+
**Example:**
133+
```
134+
get_example_details(
135+
module_id="terraform-ibm-modules/vpc/ibm",
136+
example_path="examples/basic"
137+
)
138+
```
139+
140+
**Context-efficient workflow:**
141+
1. `list_content` - see what examples exist (lightweight)
142+
2. `get_example_details` - verify it matches needs (medium, optional but recommended)
143+
3. `get_content` - fetch only the necessary code (heavy, be selective with filters!)
144+
145+
---
146+
147+
## get_content
148+
149+
Fetch actual source code and files from the GitHub repository. **This is the heaviest tool** - use filters aggressively to minimize context pollution.
150+
151+
**When to use:**
152+
- User wants to see actual terraform code
153+
- After `list_content` identified the right example
154+
- You've verified the content is relevant (via `get_example_details` or descriptions)
155+
156+
**Context efficiency tips:**
157+
- Always use `include_files` to fetch only what's needed
158+
- For examples, `include_files=["*.tf"]` excludes README and other docs
159+
- For understanding usage, `include_files=["README.md", "main.tf"]` may be sufficient
160+
- Avoid fetching test files, CI configs, or other irrelevant content
161+
162+
**Parameters:**
163+
```
164+
module_id (required):
165+
- "terraform-ibm-modules/vpc/ibm" (latest version)
166+
- "terraform-ibm-modules/vpc/ibm/7.19.0" (specific version)
167+
path (optional):
168+
- "" (root, default)
169+
- "examples/basic"
170+
- "modules/submodule-name"
171+
include_files (optional): List of glob patterns
172+
- ["*.tf"] - all Terraform files
173+
- ["main.tf", "variables.tf"] - specific files
174+
- ["*.md"] - all markdown files
175+
exclude_files (optional): List of glob patterns to exclude
176+
- ["*test*"] - exclude test files
177+
```
178+
179+
**Returns:** Markdown with file contents, organized by file with clear headers
180+
181+
**Common patterns (from most to least efficient):**
182+
183+
```
184+
# Most efficient: Get only terraform files from an example
185+
get_content(
186+
module_id="terraform-ibm-modules/vpc/ibm",
187+
path="examples/basic",
188+
include_files=["*.tf"]
189+
)
190+
191+
# Targeted: Get specific files only
192+
get_content(
193+
module_id="terraform-ibm-modules/vpc/ibm",
194+
path="examples/basic",
195+
include_files=["main.tf", "variables.tf"]
196+
)
197+
198+
# Less efficient: Get all files (includes README, LICENSE, etc.)
199+
# Only use when user specifically needs all context
200+
get_content(
201+
module_id="terraform-ibm-modules/vpc/ibm",
202+
path="examples/basic"
203+
)
204+
```
205+
206+
---
207+
208+
## Version Support
209+
210+
All tools support both version formats:
211+
- **Latest**: `terraform-ibm-modules/vpc/ibm` - uses the most recent published version
212+
- **Pinned**: `terraform-ibm-modules/vpc/ibm/7.19.0` - uses a specific version
213+
214+
For production use cases, recommend pinned versions for consistency.
215+
216+
---
217+
218+
## Context-Efficient Workflows
219+
220+
### "Show me an example of X"
221+
**Goal**: Get relevant example code with minimal context waste
222+
1. `search_modules` - find module ID (lightweight)
223+
2. `list_content` - see available examples (lightweight)
224+
3. `get_example_details` - verify it's the right example (medium, recommended)
225+
4. `get_content` with `include_files=["*.tf"]` - fetch only terraform files (heavy but filtered)
226+
227+
**Why this order?** Each step confirms relevance before fetching heavier content.
228+
229+
### "How do I use module X"
230+
**Goal**: Provide usage guidance without fetching unnecessary files
231+
1. `list_content` - find examples (lightweight)
232+
2. `get_example_details` - get README and interface (medium)
233+
3. Only call `get_content` if example details aren't sufficient
234+
235+
**Why?** Example details often contain enough information without fetching source code.
236+
237+
### "What inputs does module X need"
238+
**Goal**: Get module interface only
239+
1. `get_module_details` - get inputs/outputs from Registry (medium, direct from Registry)
240+
2. Explain to user
241+
242+
**Don't** fetch source code - the Registry metadata is sufficient and faster.
243+
244+
### "Help me build terraform for X"
245+
**Goal**: Provide starting point - prefer examples over raw interface
246+
1. `search_modules` - find relevant modules (lightweight)
247+
2. `list_content` - check if examples exist (lightweight)
248+
3. Choose path:
249+
- **If examples exist** (preferred): `get_example_details``get_content` (filtered)
250+
- **If no examples**: `get_module_details` → help user build from scratch
251+
252+
**Why examples first?** Working code is better context than interface documentation.

static/instructions.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ Keywords to detect this intent: "create", "build", "inputs", "outputs", "develop
169169
### Example Selection Strategy
170170
- `examples/basic` or `examples/simple` → for straightforward demos
171171
- `examples/complete` → for comprehensive usage
172-
- `solutions/` → for complex architecture patterns
173172
- Use descriptions to select the single most relevant example
174173

175174
## Optimization Principles

0 commit comments

Comments
 (0)