Skip to content

Commit f7eeb96

Browse files
authored
feat(tools): pf-4120 resource optimized searchPatternFly (#211)
* docs, experimental section for contextManagement * options, activate experimental context management * resource.pfContext, show experimental stats * tools, activate shouldRegister for contextManagement * tool.searchPf, resource responses, 2 tools into 1
1 parent 05053d7 commit f7eeb96

21 files changed

Lines changed: 816 additions & 15 deletions

docs/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ Welcome to the PatternFly MCP Server documentation. This guide is organized by u
55
### 🚀 Usage
66
- **[MCP Tools and Resources](./usage.md)**: Use built-in tools and resources like `searchPatternFlyDocs` and `usePatternFlyDocs`.
77
- **[Client Configuration](./usage.md)**: Configure the server for your environment.
8+
- **[Experimental settings](./experimental.md)**: Opt-in flags that may change; not documented in the stable usage guides.
89
- **[Troubleshooting](./usage.md#troubleshooting)**: Steps for common setup problems.
910

1011
### 🛠️ Developer reference
1112
- **[CLI Reference](./development.md#cli-usage)**: Reference of server options.
1213
- **[API Reference](./development.md#programmatic-usage)**: Using the server as a base library in your own Node.js MCP.
14+
- **[Experimental settings](./experimental.md)**: CLI and programmatic configuration for experimental flags.
1315
- **[Examples](./examples/README.md)**: Standalone snippets for HTTP transport, embedding, and custom tools.
1416

1517
### 🏗️ Architecture & design

docs/development.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Complete guide to using the PatternFly MCP Server for development including CLI
55
**Development:**
66
- [CLI usage](#cli-usage)
77
- [Programmatic usage](#programmatic-usage)
8+
- [Experimental settings](./experimental.md)
89
- [MCP tool plugins](#mcp-tool-plugins)
910
- [Initial troubleshooting](#initial-troubleshooting)
1011
- [Project maintenance](#project-maintenance)
@@ -36,7 +37,7 @@ Complete guide to using the PatternFly MCP Server for development including CLI
3637
- **Programmatic API** - The server can also be used programmatically with options. See [Programmatic usage](#programmatic-usage) for more details.
3738
- **Tool plugins** - The server can load external tool plugins at startup. See [MCP tool plugins](#mcp-tool-plugins) for more details.
3839
- **Test Mode** - When `--mode test` is used, the server redirects resource requests to the URL provided by `--mode-test-url`, enabling E2E testing without local filesystem access.
39-
- **Experimental options** - When an option is registered as experimental, use `--experimental-<lorem-ipsum>` on the CLI; for programmatic options use `experimental<LoremIpsum>`.
40+
- **Experimental options** - Opt-in flags use `--experimental-<name>` on the CLI and `experimental<Name>` programmatically. See [Experimental settings](./experimental.md) for the current list, examples, and lifecycle notes.
4041

4142
### Basic use scenarios
4243

@@ -122,7 +123,7 @@ The `start()` function accepts an optional `PfMcpOptions` object for programmati
122123
| `docsPaths` | `string[]` | Whitelist of local documentation directories resolved by `documentation:` slug. When empty (default), the slug is dormant. | `[]` |
123124

124125
#### Notes
125-
- **Experimental options** - When an option is registered as experimental use `experimental<LoremIpsum>` for programmatic options; for CLI options use `--experimental-<lorem-ipsum>`.
126+
- **Experimental options** - Opt-in flags use `experimental<Name>` programmatically and `--experimental-<name>` on the CLI. See [Experimental settings](./experimental.md) for the current list and configuration examples.
126127

127128
#### Example usage
128129

docs/experimental.md

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# Experimental settings
2+
3+
Opt-in server options documented here are **not** covered by the same stability guarantees as the rest of the docs. They may change behavior, graduate to stable configuration, or be removed without a major release.
4+
5+
**Stable docs:**
6+
- [Usage guide](./usage.md) — default tools, resources, and client configuration
7+
- [Development reference](./development.md) — CLI and programmatic API for supported options
8+
9+
## How experimental options work
10+
11+
- **CLI**: `--experimental-<kebab-name>` (for example, `--experimental-context-management`)
12+
- **Programmatic**: `experimental<CamelName>` on the object passed to `start()` (for example, `experimentalContextManagement: true`)
13+
- **Startup**: The server logs a warning when any registered experimental option is enabled
14+
15+
Using an experimental flag without the `experimental` prefix (CLI or programmatic) is ignored.
16+
17+
## Lifecycle
18+
19+
1. **Experimental** — documented only on this page; behavior may change between releases.
20+
2. **Graduating** — when a flag loses its experimental prefix in code, its documentation moves to [usage](./usage.md) or [development](./development.md) in the same change; remove it from the index below.
21+
3. **Removed** — when a flag fails to graduate, delete the row and section here; stable docs should not need updates.
22+
23+
## Index
24+
25+
| Internal name | CLI flag | Programmatic option | Value type |
26+
|---------------------|-------------------------------------|---------------------------------|-------------|
27+
| `contextManagement` | `--experimental-context-management` | `experimentalContextManagement` | `boolean` |
28+
29+
---
30+
31+
## contextManagement
32+
33+
Context management (also called **token-saver mode**) switches the server from the default two-step search-and-fetch workflow to a resource-link workflow for MCP clients that read `patternfly://` URIs directly.
34+
35+
> `contextManagement` is part of a broader set of updates intended to optimize the PatternFly MCP server's use of MCP resources and streamline code. Additional refactors may be included under this umbrella under later releases.
36+
37+
| Mode | Registered tools | Typical workflow |
38+
|-------------------------|-------------------------------------------------------|----------------------------------------------------------------------------------|
39+
| **Default** _(off)_ | `searchPatternFlyDocs`, `usePatternFlyDocs` | Search returns text with URLs and names; fetch content with `usePatternFlyDocs`. |
40+
| **Context management** | `searchPatternFly` only | Search returns `resource_link` items; read content with `resources/read`. |
41+
42+
Built-in MCP resources (`patternfly://docs/...`, `patternfly://schemas/...`, indexes, and `patternfly://context`) remain available in both modes.
43+
44+
### Tool: searchPatternFly
45+
46+
Registered only when context management is enabled.
47+
48+
Search PatternFly components, documentation, guidelines, and JSON schemas by keyword. Returns MCP `resource_link` content items (collections, docs, and schemas).
49+
50+
**Parameters:**
51+
- `query`: `string` (required) — Case-insensitive, full or partial keyword query (e.g., `"button"`, `"react"`, `"*"` for all resources)
52+
- `version`: `string` (optional) — Filter by PatternFly version (`"current"`, `"latest"`, or `"v6"`)
53+
54+
**Example:**
55+
```json
56+
{
57+
"query": "button"
58+
}
59+
```
60+
61+
### CLI
62+
63+
```bash
64+
npx -y @patternfly/patternfly-mcp@latest --experimental-context-management
65+
```
66+
67+
HTTP transport:
68+
69+
```bash
70+
npx -y @patternfly/patternfly-mcp@latest --http --port 8080 --experimental-context-management
71+
```
72+
73+
### Programmatic
74+
75+
```typescript
76+
import { start } from '@patternfly/patternfly-mcp';
77+
78+
const server = await start({
79+
experimentalContextManagement: true
80+
});
81+
```
82+
83+
### MCP client configuration
84+
85+
Stdio:
86+
87+
```json
88+
{
89+
"mcpServers": {
90+
"patternfly-mcp": {
91+
"command": "npx",
92+
"args": [
93+
"-y",
94+
"@patternfly/patternfly-mcp@latest",
95+
"--experimental-context-management"
96+
],
97+
"description": "PatternFly rules and documentation (experimental context management)"
98+
}
99+
}
100+
}
101+
```
102+
103+
HTTP:
104+
105+
```json
106+
{
107+
"mcpServers": {
108+
"patternfly-mcp": {
109+
"command": "npx",
110+
"args": [
111+
"-y",
112+
"@patternfly/patternfly-mcp@latest",
113+
"--http",
114+
"--port",
115+
"8080",
116+
"--experimental-context-management"
117+
],
118+
"description": "PatternFly rules and documentation (HTTP, experimental context management)"
119+
}
120+
}
121+
}
122+
```

docs/usage.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ A comprehensive guide to PatternFly MCP Server tools, resources, and configurati
77
- [Built-in resources](#built-in-resources)
88
- [MCP client configuration](#mcp-client-configuration)
99
- [Custom MCP tool plugins](#custom-mcp-tool-plugins)
10+
- [Experimental settings](./experimental.md)
1011
- [Troubleshooting](#troubleshooting)
1112

1213
## Built-in tools

src/__tests__/__snapshots__/options.defaults.test.ts.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
exports[`options defaults should return specific properties: defaults 1`] = `
44
{
5+
"contextManagement": false,
56
"contextPath": "/",
67
"contextUrl": "file:///",
78
"docsPathSlug": "documentation:",
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
2+
3+
exports[`searchPatternFlyTool should have a consistent return structure: structure 1`] = `
4+
{
5+
"callback": [Function],
6+
"name": "searchPatternFly",
7+
"schema": true,
8+
}
9+
`;
10+
11+
exports[`searchPatternFlyTool, callback should have a specific markdown format: Button 1`] = `
12+
[
13+
{
14+
"text": "# Search results for PatternFly version "v6" and "button".
15+
Found 2 collections with 5 related resources. Use the attached resources to access and read full content.",
16+
"type": "text",
17+
},
18+
{
19+
"description": "A resource collection series for Button",
20+
"groupId": "123456",
21+
"mimeType": "text/markdown",
22+
"name": "Button (Collection)",
23+
"type": "resource_link",
24+
"uri": "patternfly://docs/123456",
25+
},
26+
{
27+
"description": "Design Guidelines",
28+
"groupId": "123456",
29+
"mimeType": "text/markdown",
30+
"name": "Button - Design (v6)",
31+
"type": "resource_link",
32+
"uri": "patternfly://docs/34567b",
33+
},
34+
{
35+
"description": "Component JSON schema with property definitions for Button.",
36+
"groupId": "123456",
37+
"mimeType": "text/markdown",
38+
"name": "Button - JSON Schema (v6)",
39+
"type": "resource_link",
40+
"uri": "patternfly://schemas/67b890",
41+
},
42+
{
43+
"description": "A resource collection series for Lorem Button",
44+
"groupId": "654321",
45+
"mimeType": "text/markdown",
46+
"name": "Lorem Button (Collection)",
47+
"type": "resource_link",
48+
"uri": "patternfly://docs/654321",
49+
},
50+
{
51+
"description": "Design Guidelines",
52+
"groupId": "654321",
53+
"mimeType": "text/markdown",
54+
"name": "Lorem Button - Design (v6)",
55+
"type": "resource_link",
56+
"uri": "patternfly://docs/e34567",
57+
},
58+
{
59+
"description": "Design Guidelines",
60+
"groupId": "654321",
61+
"mimeType": "text/markdown",
62+
"name": "Lorem Button - Guidelines (v6)",
63+
"type": "resource_link",
64+
"uri": "patternfly://docs/34567",
65+
},
66+
{
67+
"description": "Component JSON schema with property definitions for Lorem Button.",
68+
"groupId": "654321",
69+
"mimeType": "text/markdown",
70+
"name": "Lorem Button - JSON Schema (v6)",
71+
"type": "resource_link",
72+
"uri": "patternfly://schemas/678e90",
73+
},
74+
]
75+
`;
76+
77+
exports[`searchPatternFlyTool, callback should parse parameters, exact match 1`] = `"# Search results for PatternFly version "v6" and "button"."`;
78+
79+
exports[`searchPatternFlyTool, callback should parse parameters, wildcard search 1`] = `"# Search results for PatternFly version "v6" and "all" resources."`;

src/__tests__/resource.patternFlyContext.test.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,33 @@ describe('resourceCallback', () => {
3030
{
3131
description: 'default',
3232
expected: 'Troubleshooting'
33+
},
34+
{
35+
description: 'contextManagement enabled',
36+
options: {
37+
contextManagement: true,
38+
experimental: ['contextManagement'],
39+
mode: 'test',
40+
version: '1.0.0',
41+
nodeVersion: 22
42+
},
43+
expected: [
44+
'search, list and access',
45+
'list and access available documentation resources',
46+
'Active Experimental Features',
47+
'contextManagement'
48+
]
3349
}
34-
])('should return context content, $description', async ({ expected }) => {
35-
const result = await resourceCallback(undefined as any);
50+
])('should return context content, $description', async ({ options, expected }) => {
51+
const result = await resourceCallback(new URL('patternfly://context'), options as any);
3652

3753
expect(result.contents).toBeDefined();
38-
expect(Object.keys(result.contents[0] as any)).toEqual(['uri', 'mimeType', 'text']);
39-
expect(result.contents[0]?.text).toContain(expected);
54+
const text = result.contents[0]?.text;
55+
56+
if (Array.isArray(expected)) {
57+
expected.forEach(snippet => expect(text).toContain(snippet));
58+
} else {
59+
expect(text).toContain(expected);
60+
}
4061
});
4162
});

src/__tests__/server.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,13 @@ describe('runServer', () => {
9090
it.each([
9191
{
9292
description: 'use default tools, stdio',
93-
options: { name: 'test-server-1', version: '1.0.0' },
93+
options: { name: 'test-server-1', version: '1.0.0', contextManagement: undefined },
9494
tools: undefined,
9595
transportMethod: MockStdioServerTransport
9696
},
9797
{
9898
description: 'use default tools, http',
99-
options: { name: 'test-server-2', version: '1.0.0', isHttp: true },
99+
options: { name: 'test-server-2', version: '1.0.0', isHttp: true, contextManagement: false },
100100
tools: undefined,
101101
transportMethod: MockStartHttpTransport
102102
},

0 commit comments

Comments
 (0)