@ibm/ibmi-mcp-server 0.1.1 โ†’ 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,88 +1,2080 @@
1
1
  # IBM i MCP Server
2
2
 
3
- The Model Context Protocol (MCP) server for IBM i systems.
3
+ <details>
4
4
 
5
- ## Quick Start
5
+ <summary><strong>Table of Contents</strong></summary>
6
+
7
+ - [IBM i MCP Server](#ibm-i-mcp-server)
8
+ - [โšก Quickstart](#-quickstart)
9
+ - [1. Create Configuration File](#1-create-configuration-file)
10
+ - [2. Create a Simple SQL Tool](#2-create-a-simple-sql-tool)
11
+ - [3. Set Configuration Path](#3-set-configuration-path)
12
+ - [4. Run the Server](#4-run-the-server)
13
+ - [5. Verify Server is Running](#5-verify-server-is-running)
14
+ - [6. Test with Python Client (Optional)](#6-test-with-python-client-optional)
15
+ - [๐ŸŽฏ What's Next?](#-whats-next)
16
+ - [CLI Reference](#cli-reference)
17
+ - [Basic Usage](#basic-usage)
18
+ - [Available Options](#available-options)
19
+ - [๐Ÿ”Œ Installing in MCP Clients](#-installing-in-mcp-clients)
20
+ - [Prerequisites: Local Installation](#prerequisites-local-installation)
21
+ - [Remote Server Setup](#remote-server-setup)
22
+ - [Client Configurations](#client-configurations)
23
+ - [๐Ÿงฉ SQL Tool Configuration](#-sql-tool-configuration)
24
+ - [Sources](#sources)
25
+ - [Tools](#tools)
26
+ - [Toolsets](#toolsets)
27
+ - [๐Ÿค– IBM i Agents](#-ibm-i-agents)
28
+ - [Key Features](#key-features)
29
+ - [Getting Started](#getting-started)
30
+ - [โš™๏ธ Configuration](#๏ธ-configuration)
31
+ - [General Authentication](#general-authentication)
32
+ - [JWT Authentication](#jwt-authentication)
33
+ - [OAuth Authentication](#oauth-authentication)
34
+ - [IBM i HTTP Authentication](#ibm-i-http-authentication)
35
+ - [Tool Loading](#tool-loading)
36
+ - [Configuration Merging](#configuration-merging)
37
+ - [Configuration Best Practices](#configuration-best-practices)
38
+ - [๐Ÿ” IBM i HTTP Authentication (Beta)](#-ibm-i-http-authentication-beta)
39
+ - [Authentication Flow](#authentication-flow)
40
+ - [Configuration](#configuration)
41
+ - [Getting Access Tokens](#getting-access-tokens)
42
+ - [Option 1: Using the Token Script (Recommended)](#option-1-using-the-token-script-recommended)
43
+ - [Sequence Overview](#sequence-overview)
44
+ - [Client Integration](#client-integration)
45
+ - [Security Considerations](#security-considerations)
46
+ - [Authentication Endpoints](#authentication-endpoints)
47
+ - [๐Ÿ› ๏ธ Running the Server (Development)](#๏ธ-running-the-server-development)
48
+ - [Building from Source](#building-from-source)
49
+ - [Transport Modes](#transport-modes)
50
+ - [HTTP Transport (Recommended for Development)](#http-transport-recommended-for-development)
51
+ - [Stdio Transport (for CLI tools and MCP Inspector)](#stdio-transport-for-cli-tools-and-mcp-inspector)
52
+ - [Session Modes (HTTP Only)](#session-modes-http-only)
53
+ - [CLI Options](#cli-options)
54
+ - [Common Development Scenarios](#common-development-scenarios)
55
+ - [Development Tips](#development-tips)
56
+ - [Troubleshooting](#troubleshooting)
57
+ - [๐Ÿ•ต๏ธโ€โ™‚๏ธ MCP Inspector](#๏ธ๏ธ-mcp-inspector)
58
+ - [Deployment](#deployment)
59
+ - [๐Ÿ—๏ธ Built With MCP TypeScript Template](#๏ธ-built-with-mcp-typescript-template)
60
+ - [Template Features Used](#template-features-used)
61
+ - [Why This Template?](#why-this-template)
62
+ - [Customizations for IBM i](#customizations-for-ibm-i)
63
+ - [Get Started with the Template](#get-started-with-the-template)
64
+
65
+ </details>
66
+
67
+ ---
68
+
69
+ ## โšก Quickstart
70
+
71
+ Get started with the IBM i MCP Server using the official npm package.
72
+
73
+ ### 1. Create Configuration File
74
+
75
+ Create a `.env` file with your IBM i connection details:
76
+
77
+ ```bash
78
+ cat > .env << 'EOF'
79
+ # IBM i DB2 for i Connection Settings
80
+ DB2i_HOST=your-ibmi-host.com
81
+ DB2i_USER=your-username
82
+ DB2i_PASS=your-password
83
+ DB2i_PORT=8076
84
+ DB2i_IGNORE_UNAUTHORIZED=true
85
+
86
+ # MCP Server Settings
87
+ MCP_TRANSPORT_TYPE=http
88
+ MCP_HTTP_PORT=3010
89
+ MCP_LOG_LEVEL=info
90
+
91
+ # Tools Configuration
92
+ TOOLS_YAML_PATH=./tools
93
+ EOF
94
+ ```
95
+
96
+ > **๐Ÿ“– Configuration Guide:** See the complete [Configuration](#โš™๏ธ-configuration) section for all available settings.
97
+
98
+ ### 2. Create a Simple SQL Tool
99
+
100
+ Create a `tools` directory and a basic tool configuration file:
101
+
102
+ ```bash
103
+ mkdir -p tools
104
+ ```
105
+
106
+ <details>
107
+ <summary><strong>๐Ÿ“„ Click to copy: tools/quickstart.yaml</strong></summary>
108
+
109
+ ```yaml
110
+ sources:
111
+ ibmi-system:
112
+ host: ${DB2i_HOST}
113
+ user: ${DB2i_USER}
114
+ password: ${DB2i_PASS}
115
+ port: 8076
116
+ ignore-unauthorized: true
117
+
118
+ tools:
119
+ system_status:
120
+ source: ibmi-system
121
+ description: "Overall system performance statistics with CPU, memory, and I/O metrics"
122
+ parameters: []
123
+ statement: |
124
+ SELECT * FROM TABLE(QSYS2.SYSTEM_STATUS(RESET_STATISTICS=>'YES',DETAILED_INFO=>'ALL')) X
125
+
126
+ system_activity:
127
+ source: ibmi-system
128
+ description: "Current system activity information including active jobs and resource utilization"
129
+ parameters: []
130
+ statement: |
131
+ SELECT * FROM TABLE(QSYS2.SYSTEM_ACTIVITY_INFO())
132
+
133
+ active_job_info:
134
+ source: ibmi-system
135
+ description: "Find the top 10 consumers of CPU in the QUSRWRK and QSYSWRK subsystems"
136
+ parameters:
137
+ - name: limit
138
+ type: integer
139
+ default: 10
140
+ description: "Number of top CPU consumers to return"
141
+ statement: |
142
+ SELECT CPU_TIME, A.* FROM
143
+ TABLE(QSYS2.ACTIVE_JOB_INFO(SUBSYSTEM_LIST_FILTER => 'QUSRWRK,QSYSWRK')) A
144
+ ORDER BY CPU_TIME DESC
145
+ FETCH FIRST :limit ROWS ONLY
146
+
147
+ toolsets:
148
+ performance:
149
+ tools:
150
+ - system_status
151
+ - system_activity
152
+ - active_job_info
153
+ ```
154
+
155
+ </details>
156
+
157
+ Create the file:
158
+
159
+ ```bash
160
+ cat > tools/quickstart.yaml << 'EOF'
161
+ sources:
162
+ ibmi-system:
163
+ host: ${DB2i_HOST}
164
+ user: ${DB2i_USER}
165
+ password: ${DB2i_PASS}
166
+ port: 8076
167
+ ignore-unauthorized: true
168
+
169
+ tools:
170
+ system_status:
171
+ source: ibmi-system
172
+ description: "Overall system performance statistics with CPU, memory, and I/O metrics"
173
+ parameters: []
174
+ statement: |
175
+ SELECT * FROM TABLE(QSYS2.SYSTEM_STATUS(RESET_STATISTICS=>'YES',DETAILED_INFO=>'ALL')) X
176
+
177
+ system_activity:
178
+ source: ibmi-system
179
+ description: "Current system activity information including active jobs and resource utilization"
180
+ parameters: []
181
+ statement: |
182
+ SELECT * FROM TABLE(QSYS2.SYSTEM_ACTIVITY_INFO())
183
+
184
+ active_job_info:
185
+ source: ibmi-system
186
+ description: "Find the top 10 consumers of CPU in the QUSRWRK and QSYSWRK subsystems"
187
+ parameters:
188
+ - name: limit
189
+ type: integer
190
+ default: 10
191
+ description: "Number of top CPU consumers to return"
192
+ statement: |
193
+ SELECT CPU_TIME, A.* FROM
194
+ TABLE(QSYS2.ACTIVE_JOB_INFO(SUBSYSTEM_LIST_FILTER => 'QUSRWRK,QSYSWRK')) A
195
+ ORDER BY CPU_TIME DESC
196
+ FETCH FIRST :limit ROWS ONLY
197
+
198
+ toolsets:
199
+ performance:
200
+ tools:
201
+ - system_status
202
+ - system_activity
203
+ - active_job_info
204
+ EOF
205
+ ```
206
+
207
+ This creates three tools:
208
+ - **`system_status`** - System performance metrics
209
+ - **`system_activity`** - Current activity information
210
+ - **`active_job_info`** - Top CPU consumers (with customizable limit parameter)
211
+
212
+ > [!NOTE]
213
+ > **๐Ÿ“– More Tools:** The repository includes many ready-to-use tools in the [`tools/`](../tools/) directory covering performance monitoring, security, job management, and more. See [SQL Tool Configuration](#-sql-tool-configuration) to create your own custom tools.
214
+
215
+ ### 3. Set Configuration Path
216
+
217
+ Point the server to your configuration file using the `MCP_SERVER_CONFIG` environment variable:
218
+
219
+ ```bash
220
+ # Set configuration file path
221
+ export MCP_SERVER_CONFIG=.env
222
+ ```
223
+
224
+ > **Note:** CLI arguments override settings in the configuration file.
225
+
226
+ ### 4. Run the Server
227
+
228
+ Start the server in HTTP mode with your new tools:
229
+
230
+ ```bash
231
+ # Start the server with HTTP transport
232
+ npx -y @ibm/ibmi-mcp-server@latest --transport http --tools ./tools/quckstart.yaml
233
+ ```
234
+
235
+ The server will:
236
+ - Load configuration from `.env` (via `MCP_SERVER_CONFIG`)
237
+ - Connect to your IBM i system via Mapepire
238
+ - Start on `http://localhost:3010/mcp`
239
+ - Load the SQL tools from `tools/quickstart.yaml`
240
+
241
+
242
+
243
+ ### 5. Verify Server is Running
244
+
245
+ Test the server endpoint:
246
+
247
+ ```bash
248
+ # Check health
249
+ curl http://localhost:3010/healthz
250
+
251
+ # List available tools (requires running server)
252
+ curl -X POST http://localhost:3010/mcp \
253
+ -H "Content-Type: application/json" \
254
+ -d '{"jsonrpc":"2.0","method":"tools/list","params":{},"id":1}'
255
+ ```
256
+
257
+ ### 6. Test with Python Client (Optional)
258
+
259
+ Install and run the example Python client:
260
+
261
+ ```bash
262
+ # Navigate to client directory
263
+ cd client/
264
+
265
+ # Install dependencies with uv
266
+ uv sync
267
+
268
+ # List available tools
269
+ uv run mcp_client.py
270
+
271
+ # Run agent with LLM (requires API key)
272
+ export OPENAI_API_KEY=your-api-key
273
+ uv run agent.py -p "What is my system status?"
274
+ ```
275
+
276
+ > **๐Ÿ“– Client Documentation:** See [client/README.md](../client/README.md) for detailed setup instructions.
277
+
278
+ > [!TIP]
279
+ > **Explore More SQL Tools:** The `tools/` directory contains many ready-to-use SQL tool configurations for common IBM i tasks. Browse the collection and customize them for your needs. See the [Tools Guide](../tools/README.md) for more details.
280
+
281
+ ---
282
+
283
+ ## ๐ŸŽฏ What's Next?
284
+
285
+ Choose your path based on what you want to accomplish:
286
+
287
+ | Path | Guide | Description |
288
+ |------|-------|-------------|
289
+ | **MCP Client Integration** | [Installing in MCP Clients](#-installing-in-mcp-clients) | Connect to Claude Desktop, VSCode, Cursor, and other MCP clients |
290
+ | **Custom SQL Tools** | [SQL Tool Configuration](#-sql-tool-configuration) | Create YAML-based SQL tools for your IBM i use cases |
291
+ | **Server Configuration** | [Configuration Guide](#๏ธ-configuration) | Explore authentication, transport modes, and environment variables |
292
+ | **Production Deployment** | [Deployment Options](../deployment/README.md) | Deploy with Docker, Podman, or OpenShift |
293
+ | **AI Agent Development** | [IBM i Agents](#-ibm-i-agents) | Build custom AI agents that interact with IBM i systems |
294
+ | **Development & Contributing** | [Running the Server (Development)](#๏ธ-running-the-server-development) | Build from source, run tests, and contribute |
295
+
296
+ ---
297
+
298
+ ## CLI Reference
299
+
300
+ The IBM i MCP Server provides a command-line interface with flexible options for running and configuring the server.
301
+
302
+ ### Basic Usage
303
+
304
+ ```bash
305
+ npx -y @ibm/ibmi-mcp-server@latest [options]
306
+ ```
307
+
308
+ > **Note:** The `-y` flag automatically accepts the npm package installation prompt.
309
+
310
+ ### Available Options
311
+
312
+ | Option | Description |
313
+ |--------|-------------|
314
+ | `--tools <path>` | Path to YAML tools (file, directory, or glob pattern) |
315
+ | `--toolsets <list>` | Comma-separated list of toolsets to load |
316
+ | `--list-toolsets` | List all available toolsets and exit |
317
+ | `--transport <type>` | Transport type: `stdio` (default) or `http` |
318
+ | `--help` | Show help message |
319
+
320
+ <details>
321
+ <summary><strong>Common Examples</strong></summary>
322
+
323
+ **Run server with stdio transport (for MCP clients):**
324
+ ```bash
325
+ npx -y @ibm/ibmi-mcp-server@latest --transport stdio --tools ./tools
326
+ ```
327
+
328
+ **Run HTTP server for testing:**
329
+ ```bash
330
+ npx -y @ibm/ibmi-mcp-server@latest --transport http --tools ./tools
331
+ ```
332
+
333
+ **Load specific toolsets only:**
334
+ ```bash
335
+ npx -y @ibm/ibmi-mcp-server@latest --toolsets performance,security
336
+ ```
337
+
338
+ **List available toolsets:**
339
+ ```bash
340
+ npx -y @ibm/ibmi-mcp-server@latest --list-toolsets --tools ./tools
341
+ ```
342
+
343
+ **Use custom tools directory:**
344
+ ```bash
345
+ npx -y @ibm/ibmi-mcp-server@latest --tools /absolute/path/to/custom-tools
346
+ ```
347
+
348
+ </details>
349
+
350
+ ---
351
+
352
+ ## ๐Ÿ”Œ Installing in MCP Clients
353
+
354
+ This server can be integrated into any MCP-compatible client using either **local** (stdio) or **remote** (HTTP) connections.
355
+
356
+ ### Prerequisites: Local Installation
357
+
358
+ The server is available as an npm package and can be used directly with `npx`:
359
+
360
+ ```bash
361
+ # Test the server is available
362
+ npx -y @ibm/ibmi-mcp-server@latest --help
363
+ ```
364
+
365
+ > **Note:** The `-y` flag automatically accepts the npm package installation prompt.
366
+ > `TOOLS_YAML_PATH` must be an **absolute path** to your tools configuration directory (e.g., `/full/path/to/tools`).
367
+
368
+ ### Remote Server Setup
369
+
370
+ For HTTP remote connections, you need to:
371
+
372
+ 1. **Start the server with IBM i authentication enabled:**
373
+
374
+ ```bash
375
+ # Ensure your .env has these settings:
376
+ MCP_AUTH_MODE=ibmi
377
+ IBMI_HTTP_AUTH_ENABLED=true
378
+ IBMI_AUTH_ALLOW_HTTP=true # For development only!
379
+
380
+ npm run start:http
381
+ ```
382
+
383
+ 2. **Obtain an access token:**
384
+
385
+ ```bash
386
+ # Use the token script to authenticate
387
+ node get-access-token.js --verbose
388
+
389
+ # Or set it directly in your environment
390
+ export IBMI_MCP_ACCESS_TOKEN="your-token-here"
391
+ ```
392
+
393
+ See [IBM i HTTP Authentication](#ibm-i-http-authentication-beta) for detailed authentication setup.
394
+
395
+ 3. **Configure your client** with the server URL and Bearer token (examples below).
396
+
397
+ > **โš ๏ธ Production Note:** Replace `http://localhost:3010` with your production endpoint URL and ensure HTTPS is enabled (`IBMI_AUTH_ALLOW_HTTP=false`).
398
+
399
+ In production environments, it is strongly recommended to deploy the MCP server behind a reverse proxy server such as Nginx, HAProxy, or Caddy. The reverse proxy server can provide TLS/SSL termination for the MCP server to handle HTTPS connections and SSL/TLS certificate management. Below is an example of an Nginx configuration. You may need to adjust it according to your specific networking configuration and security requirements.
400
+
401
+ ```
402
+ pid /run/nginx.pid;
403
+ events {}
404
+ http {
405
+ server {
406
+ listen 443 ssl;
407
+ ssl_certificate <path_to_certificate>;
408
+ ssl_certificate_key <path_to_privatekey>;
409
+ ssl_protocols TLSv1.3;
410
+ ssl_ciphers HIGH:!aNULL:!MD5;
411
+ ssl_session_cache shared:SSL:50m;
412
+ ssl_prefer_server_ciphers on;
413
+ # This is needed for getting access token when IBM i HTTP authentication enabled with HTTPS only
414
+ proxy_set_header X-Forwarded-Proto https;
415
+ location / {
416
+ proxy_pass http://mcp_server;
417
+ }
418
+ }
419
+ upstream mcp_server {
420
+ server 127.0.0.1:3010;
421
+ }
422
+ }
423
+ ```
424
+
425
+ ---
426
+
427
+ ### Client Configurations
428
+
429
+ <details>
430
+ <summary><strong>Claude Code</strong></summary>
431
+
432
+ Claude Code supports both local (stdio) and remote (HTTP) MCP server connections. You can configure servers using the CLI or by editing `.mcp.json` directly.
433
+
434
+ #### Option 1: Local Stdio Server (Recommended)
435
+
436
+ **Using CLI:**
437
+ ```bash
438
+ # Add local stdio server
439
+ claude mcp add ibmi-mcp \
440
+ --env DB2i_HOST=your-ibmi-host.com \
441
+ --env DB2i_USER=your-username \
442
+ --env DB2i_PASS=your-password \
443
+ --env DB2i_PORT=8076 \
444
+ --env MCP_TRANSPORT_TYPE=stdio \
445
+ -- npx -y @ibm/ibmi-mcp-server@latest --transport stdio --tools /absolute/path/to/tools
446
+ ```
447
+
448
+ **Using `.mcp.json`:**
449
+ ```json
450
+ {
451
+ "mcpServers": {
452
+ "ibmi-mcp": {
453
+ "command": "npx",
454
+ "args": ["@ibm/ibmi-mcp-server@latest", "-y", "--transport", "stdio", "--tools", "/absolute/path/to/tools"],
455
+ "env": {
456
+ "DB2i_HOST": "your-ibmi-host.com",
457
+ "DB2i_USER": "your-username",
458
+ "DB2i_PASS": "your-password",
459
+ "DB2i_PORT": "8076",
460
+ "NODE_OPTIONS": "--no-deprecation"
461
+ }
462
+ }
463
+ }
464
+ }
465
+ ```
466
+
467
+ #### Option 2: Remote HTTP Server
468
+
469
+ **Using CLI:**
470
+ ```bash
471
+ # Add remote HTTP server with authentication
472
+ claude mcp add --transport http ibmi-mcp http://localhost:3010/mcp \
473
+ --header "Authorization: Bearer YOUR_ACCESS_TOKEN_HERE"
474
+ ```
475
+
476
+ **Using `.mcp.json`:**
477
+ ```json
478
+ {
479
+ "mcpServers": {
480
+ "ibmi-mcp": {
481
+ "url": "http://localhost:3010/mcp",
482
+ "type": "http",
483
+ "headers": {
484
+ "Authorization": "Bearer YOUR_ACCESS_TOKEN_HERE"
485
+ }
486
+ }
487
+ }
488
+ }
489
+ ```
490
+
491
+ #### Environment Variable Expansion
492
+
493
+ Claude Code supports environment variable expansion in `.mcp.json` files, allowing you to keep credentials secure:
494
+
495
+ ```json
496
+ {
497
+ "mcpServers": {
498
+ "ibmi-mcp": {
499
+ "command": "npx",
500
+ "args": ["@ibm/ibmi-mcp-server@latest", "-y", "--transport", "stdio", "--tools", "${IBMI_TOOLS_PATH}"],
501
+ "env": {
502
+ "DB2i_HOST": "${DB2i_HOST}",
503
+ "DB2i_USER": "${DB2i_USER}",
504
+ "DB2i_PASS": "${DB2i_PASS}",
505
+ "DB2i_PORT": "${DB2i_PORT:-8076}"
506
+ }
507
+ }
508
+ }
509
+ }
510
+ ```
511
+
512
+ **Supported syntax:**
513
+ - `${VAR}` - Expands to the value of environment variable `VAR`
514
+ - `${VAR:-default}` - Expands to `VAR` if set, otherwise uses `default`
515
+
516
+ #### Managing Servers
517
+
518
+ ```bash
519
+ # List configured servers
520
+ claude mcp list
521
+
522
+ # Get server details
523
+ claude mcp get ibmi-mcp
524
+
525
+ # Remove a server
526
+ claude mcp remove ibmi-mcp
527
+
528
+ # Check server status in Claude Code
529
+ /mcp
530
+ ```
531
+
532
+ > ๐Ÿ“– [Claude Code MCP Documentation](https://docs.claude.com/en/docs/claude-code/mcp)
533
+
534
+ </details>
535
+
536
+ <details>
537
+ <summary><strong>Claude Desktop</strong></summary>
538
+
539
+ #### Local (Stdio)
540
+
541
+ Edit `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS) or `%APPDATA%\Claude\claude_desktop_config.json` (Windows):
542
+
543
+ ```json
544
+ {
545
+ "mcpServers": {
546
+ "ibmi-mcp": {
547
+ "command": "npx",
548
+ "args": ["@ibm/ibmi-mcp-server@latest", "-y", "--transport", "stdio", "--tools", "/absolute/path/to/tools"],
549
+ "env": {
550
+ "DB2i_HOST": "your-ibmi-host.com",
551
+ "DB2i_USER": "your-username",
552
+ "DB2i_PASS": "your-password",
553
+ "DB2i_PORT": "8076"
554
+ }
555
+ }
556
+ }
557
+ }
558
+ ```
559
+
560
+ #### Remote (HTTP)
561
+
562
+ ```json
563
+ {
564
+ "mcpServers": {
565
+ "ibmi-mcp": {
566
+ "url": "http://localhost:3010/mcp",
567
+ "type": "http",
568
+ "headers": {
569
+ "Authorization": "Bearer YOUR_ACCESS_TOKEN_HERE"
570
+ }
571
+ }
572
+ }
573
+ }
574
+ ```
575
+
576
+ > ๐Ÿ“– [Claude Desktop MCP Setup](https://modelcontextprotocol.io/quickstart/user)
577
+
578
+ </details>
579
+
580
+ <details>
581
+ <summary><strong>VSCode</strong></summary>
582
+
583
+ VSCode supports MCP servers through Copilot Chat. You can configure servers at the user or workspace level using configuration files or the CLI.
584
+
585
+ **Prerequisites:** Ensure [GitHub Copilot](https://marketplace.visualstudio.com/items?itemName=GitHub.copilot) is installed and enabled.
586
+
587
+ #### Configuration File Locations
588
+
589
+ - **Workspace:** `.vscode/mcp.json` (shared with team via version control)
590
+ - **User:** `mcp.json` in your user profile directory
591
+ - macOS/Linux: `~/.config/Code/User/globalStorage/modelcontextprotocol.mcp/mcp.json`
592
+ - Windows: `%APPDATA%\Code\User\globalStorage\modelcontextprotocol.mcp\mcp.json`
593
+
594
+ #### Option 1: Local Stdio Server
595
+
596
+ **Using CLI:**
597
+ ```bash
598
+ # Add local stdio server
599
+ code --add-mcp '{
600
+ "name": "ibmiMcp",
601
+ "type": "stdio",
602
+ "command": "npx",
603
+ "args": ["@ibm/ibmi-mcp-server@latest", "-y", "--transport", "stdio", "--tools", "/absolute/path/to/tools"],
604
+ "env": {
605
+ "DB2i_HOST": "your-ibmi-host.com",
606
+ "DB2i_USER": "your-username",
607
+ "DB2i_PASS": "your-password",
608
+ "DB2i_PORT": "8076"
609
+ }
610
+ }'
611
+ ```
612
+
613
+ **Using `mcp.json`:**
614
+ ```json
615
+ {
616
+ "servers": {
617
+ "ibmiMcp": {
618
+ "type": "stdio",
619
+ "command": "npx",
620
+ "args": ["@ibm/ibmi-mcp-server@latest", "-y", "--transport", "stdio", "--tools", "/absolute/path/to/tools"],
621
+ "env": {
622
+ "DB2i_HOST": "your-ibmi-host.com",
623
+ "DB2i_USER": "your-username",
624
+ "DB2i_PASS": "your-password",
625
+ "DB2i_PORT": "8076"
626
+ }
627
+ }
628
+ }
629
+ }
630
+ ```
631
+
632
+ #### Option 2: Remote HTTP Server
633
+
634
+ **Using CLI:**
635
+ ```bash
636
+ # Add remote HTTP server
637
+ code --add-mcp '{
638
+ "name": "ibmiMcp",
639
+ "type": "http",
640
+ "url": "http://localhost:3010/mcp",
641
+ "headers": {
642
+ "Authorization": "Bearer YOUR_ACCESS_TOKEN_HERE"
643
+ }
644
+ }'
645
+ ```
646
+
647
+ **Using `mcp.json`:**
648
+ ```json
649
+ {
650
+ "servers": {
651
+ "ibmiMcp": {
652
+ "type": "http",
653
+ "url": "http://localhost:3010/mcp",
654
+ "headers": {
655
+ "Authorization": "Bearer YOUR_ACCESS_TOKEN_HERE"
656
+ }
657
+ }
658
+ }
659
+ }
660
+ ```
661
+
662
+ #### Secure Credentials with Input Variables
663
+
664
+ VSCode supports input variables to avoid hardcoding sensitive credentials:
665
+
666
+ ```json
667
+ {
668
+ "inputs": [
669
+ {
670
+ "id": "db2iHost",
671
+ "type": "promptString",
672
+ "description": "IBM i DB2 host address"
673
+ },
674
+ {
675
+ "id": "db2iUser",
676
+ "type": "promptString",
677
+ "description": "IBM i username"
678
+ },
679
+ {
680
+ "id": "db2iPass",
681
+ "type": "promptString",
682
+ "description": "IBM i password",
683
+ "password": true
684
+ }
685
+ ],
686
+ "servers": {
687
+ "ibmiMcp": {
688
+ "type": "stdio",
689
+ "command": "npx",
690
+ "args": ["@ibm/ibmi-mcp-server@latest", "-y", "--transport", "stdio", "--tools", "/absolute/path/to/tools"],
691
+ "env": {
692
+ "DB2i_HOST": "${input:db2iHost}",
693
+ "DB2i_USER": "${input:db2iUser}",
694
+ "DB2i_PASS": "${input:db2iPass}",
695
+ "DB2i_PORT": "8076"
696
+ }
697
+ }
698
+ }
699
+ }
700
+ ```
701
+
702
+ VSCode will prompt for these values when the server starts, keeping credentials secure.
703
+
704
+ #### Managing Servers
705
+
706
+ - **View servers:** Check the Copilot Chat view in the Activity Bar
707
+ - **Restart server:** Use Command Palette (`Cmd/Ctrl+Shift+P`) โ†’ "MCP: Restart Server"
708
+ - **Disable server:** Remove from `mcp.json` or disable in settings
709
+
710
+ > ๐Ÿ“– [VSCode MCP Documentation](https://code.visualstudio.com/docs/copilot/customization/mcp-servers)
711
+
712
+ </details>
713
+
714
+ <details>
715
+ <summary><strong>Cursor</strong></summary>
716
+
717
+ #### Local (Stdio)
718
+
719
+ Add to Cursor settings or `.cursor/mcp.json`:
720
+
721
+ ```json
722
+ {
723
+ "mcpServers": {
724
+ "ibmi-mcp": {
725
+ "command": "npx",
726
+ "args": ["@ibm/ibmi-mcp-server@latest", "-y", "--transport", "stdio", "--tools", "/absolute/path/to/tools"],
727
+ "env": {
728
+ "DB2i_HOST": "your-ibmi-host.com",
729
+ "DB2i_USER": "your-username",
730
+ "DB2i_PASS": "your-password",
731
+ "DB2i_PORT": "8076"
732
+ }
733
+ }
734
+ }
735
+ }
736
+ ```
737
+
738
+ #### Remote (HTTP)
739
+
740
+ ```json
741
+ {
742
+ "mcpServers": {
743
+ "ibmi-mcp": {
744
+ "url": "http://localhost:3010/mcp",
745
+ "type": "http",
746
+ "headers": {
747
+ "Authorization": "Bearer YOUR_ACCESS_TOKEN_HERE"
748
+ }
749
+ }
750
+ }
751
+ }
752
+ ```
753
+
754
+ > ๐Ÿ“– [Cursor MCP Documentation](https://docs.cursor.com/context/model-context-protocol)
755
+
756
+ </details>
757
+
758
+ <details>
759
+ <summary><strong>Windsurf</strong></summary>
760
+
761
+ #### Local (Stdio)
762
+
763
+ Add to Windsurf configuration:
764
+
765
+ ```json
766
+ {
767
+ "mcpServers": {
768
+ "ibmi-mcp": {
769
+ "command": "npx",
770
+ "args": ["@ibm/ibmi-mcp-server@latest", "-y", "--transport", "stdio", "--tools", "/absolute/path/to/tools"],
771
+ "env": {
772
+ "DB2i_HOST": "your-ibmi-host.com",
773
+ "DB2i_USER": "your-username",
774
+ "DB2i_PASS": "your-password",
775
+ "DB2i_PORT": "8076"
776
+ }
777
+ }
778
+ }
779
+ }
780
+ ```
781
+
782
+ #### Remote (HTTP)
783
+
784
+ ```json
785
+ {
786
+ "mcpServers": {
787
+ "ibmi-mcp": {
788
+ "url": "http://localhost:3010/mcp",
789
+ "type": "http",
790
+ "headers": {
791
+ "Authorization": "Bearer YOUR_ACCESS_TOKEN_HERE"
792
+ }
793
+ }
794
+ }
795
+ }
796
+ ```
797
+
798
+ > ๐Ÿ“– [Windsurf MCP Documentation](https://docs.windsurf.com/windsurf/cascade/mcp)
799
+
800
+ </details>
801
+
802
+ <details>
803
+ <summary><strong>Roo Code</strong></summary>
804
+
805
+ #### Local (Stdio)
806
+
807
+ Configure in Roo Code settings:
808
+
809
+ ```json
810
+ {
811
+ "mcpServers": {
812
+ "ibmi-mcp": {
813
+ "command": "npx",
814
+ "args": ["@ibm/ibmi-mcp-server@latest", "-y", "--transport", "stdio", "--tools", "/absolute/path/to/tools"],
815
+ "env": {
816
+ "DB2i_HOST": "your-ibmi-host.com",
817
+ "DB2i_USER": "your-username",
818
+ "DB2i_PASS": "your-password",
819
+ "DB2i_PORT": "8076"
820
+ }
821
+ }
822
+ }
823
+ }
824
+ ```
825
+
826
+ #### Remote (HTTP)
827
+
828
+ ```json
829
+ {
830
+ "mcpServers": {
831
+ "ibmi-mcp": {
832
+ "url": "http://localhost:3010/mcp",
833
+ "type": "http",
834
+ "headers": {
835
+ "Authorization": "Bearer YOUR_ACCESS_TOKEN_HERE"
836
+ }
837
+ }
838
+ }
839
+ }
840
+ ```
841
+
842
+ > ๐Ÿ“– [Roo Code MCP Documentation](https://docs.roocode.com/features/mcp/using-mcp-in-roo)
843
+
844
+ </details>
845
+
846
+ <details>
847
+ <summary><strong>LM Studio</strong></summary>
848
+
849
+ #### Local (Stdio)
850
+
851
+ ```json
852
+ {
853
+ "mcpServers": {
854
+ "ibmi-mcp": {
855
+ "command": "npx",
856
+ "args": ["@ibm/ibmi-mcp-server@latest", "-y", "--transport", "stdio", "--tools", "/absolute/path/to/tools"],
857
+ "env": {
858
+ "DB2i_HOST": "your-ibmi-host.com",
859
+ "DB2i_USER": "your-username",
860
+ "DB2i_PASS": "your-password",
861
+ "DB2i_PORT": "8076",
862
+ "NODE_OPTIONS": "--no-deprecation"
863
+ }
864
+ }
865
+ }
866
+ }
867
+ ```
868
+
869
+ #### Remote (HTTP)
870
+
871
+ ```json
872
+ {
873
+ "mcpServers": {
874
+ "ibmi-mcp": {
875
+ "url": "http://localhost:3010/mcp",
876
+ "type": "http",
877
+ "headers": {
878
+ "Authorization": "Bearer YOUR_ACCESS_TOKEN_HERE"
879
+ }
880
+ }
881
+ }
882
+ }
883
+ ```
884
+
885
+ > ๐Ÿ“– [LM Studio MCP Support](https://lmstudio.ai/blog/lmstudio-v0.3.17)
886
+
887
+ </details>
888
+
889
+ <details>
890
+ <summary><strong>OpenCode</strong></summary>
891
+
892
+ #### Local (Stdio)
893
+
894
+ Add local MCP servers using "type": "local" within the MCP object. Multiple MCP servers can be added. The key string for each server can be any arbitrary name.
895
+
896
+ **opencode.json**:
897
+ ```json
898
+ {
899
+ "$schema": "https://opencode.ai/config.json",
900
+ "mcp": {
901
+ "ibmi-mcp": {
902
+ "type": "local",
903
+ "enabled": true,
904
+ "command": ["npx", "@ibm/ibmi-mcp-server@latest", "-y", "--transport", "stdio", "--tools", "/absolute/path/to/tools"],
905
+ "environment": {
906
+ "DB2i_HOST": "your-ibmi-host.com",
907
+ "DB2i_USER": "your-username",
908
+ "DB2i_PASS": "your-password",
909
+ "DB2i_PORT": "8076"
910
+ },
911
+ "enabled": true
912
+ }
913
+ }
914
+ }
915
+ ```
916
+
917
+ You can also disable a server by setting enabled to false. This is useful if you want to temporarily disable a server without removing it from your config.
918
+
919
+ #### Remote (HTTP)
920
+
921
+ ```json
922
+ {
923
+ "$schema": "https://opencode.ai/config.json",
924
+ "mcp": {
925
+ "ibmi-mcp": {
926
+ "type": "remote",
927
+ "enabled": true,
928
+ "url": "http://localhost:3010/mcp",
929
+ "headers": {
930
+ "Authorization": "Bearer YOUR_ACCESS_TOKEN_HERE"
931
+ }
932
+ }
933
+ }
934
+ }
935
+ ```
936
+
937
+ > ๐Ÿ“– [OpenCode MCP Documentation](https://opencode.ai/docs/mcp-servers)
938
+
939
+ </details>
940
+
941
+ <details>
942
+ <summary><strong>Gemini CLI</strong></summary>
943
+
944
+ See [Gemini CLI Configuration](https://google-gemini.github.io/gemini-cli/docs/tools/mcp-server.html) for details.
945
+ 1. Open the Gemini CLI settings file. The location is `~/.gemini/settings.json` (where `~` is your home directory).
946
+ 2. Add the following to the `mcpServers` object in your `settings.json` file:
947
+
948
+ #### Local (Stdio)
949
+
950
+ Configure in Gemini CLI settings:
951
+
952
+ ```json
953
+ {
954
+ "mcpServers": {
955
+ "ibmi-mcp": {
956
+ "command": "npx",
957
+ "args": ["@ibm/ibmi-mcp-server@latest", "-y", "--transport", "stdio", "--tools", "/absolute/path/to/tools"],
958
+ "env": {
959
+ "DB2i_HOST": "your-ibmi-host.com",
960
+ "DB2i_USER": "your-username",
961
+ "DB2i_PASS": "your-password",
962
+ "DB2i_PORT": "8076"
963
+ }
964
+ }
965
+ }
966
+ }
967
+ ```
968
+
969
+ #### Remote (HTTP)
970
+
971
+ ```json
972
+ {
973
+ "mcpServers": {
974
+ "ibmi-mcp": {
975
+ "url": "http://localhost:3010/mcp",
976
+ "type": "http",
977
+ "headers": {
978
+ "Authorization": "Bearer YOUR_ACCESS_TOKEN_HERE"
979
+ }
980
+ }
981
+ }
982
+ }
983
+ ```
984
+
985
+ > ๐Ÿ“– [Gemini CLI MCP Documentation](https://google-gemini.github.io/gemini-cli/docs/tools/mcp-server.html)
986
+
987
+ </details>
988
+
989
+ <details>
990
+ <summary><strong>Cline</strong></summary>
991
+
992
+ Cline supports MCP servers through both the marketplace and manual configuration.
993
+
994
+ **Prerequisites:** Ensure [Cline](https://marketplace.visualstudio.com/items?itemName=saoudrizwan.claude-dev) is installed in VSCode.
995
+
996
+ #### Option 1: Manual Configuration
997
+
998
+ **For Local (Stdio) Server:**
999
+
1000
+ 1. Open **Cline**
1001
+ 2. Click the hamburger menu icon (โ˜ฐ) โ†’ **MCP Servers**
1002
+ 3. Choose **Local Servers** tab
1003
+ 4. Click **Edit Configuration**
1004
+ 5. Add the configuration:
1005
+
1006
+ ```json
1007
+ {
1008
+ "mcpServers": {
1009
+ "ibmi-mcp": {
1010
+ "command": "npx",
1011
+ "args": ["@ibm/ibmi-mcp-server@latest", "-y", "--transport", "stdio", "--tools", "/absolute/path/to/tools"],
1012
+ "env": {
1013
+ "DB2i_HOST": "your-ibmi-host.com",
1014
+ "DB2i_USER": "your-username",
1015
+ "DB2i_PASS": "your-password",
1016
+ "DB2i_PORT": "8076"
1017
+ }
1018
+ }
1019
+ }
1020
+ }
1021
+ ```
1022
+
1023
+ **For Remote (HTTP) Server:**
1024
+
1025
+ 1. Open **Cline**
1026
+ 2. Click the hamburger menu icon (โ˜ฐ) โ†’ **MCP Servers**
1027
+ 3. Choose **Remote Servers** tab
1028
+ 4. Click **Edit Configuration**
1029
+ 5. Add the configuration:
1030
+
1031
+ ```json
1032
+ {
1033
+ "mcpServers": {
1034
+ "ibmi-mcp": {
1035
+ "url": "http://localhost:3010/mcp",
1036
+ "type": "streamableHttp",
1037
+ "headers": {
1038
+ "Authorization": "Bearer YOUR_ACCESS_TOKEN_HERE"
1039
+ }
1040
+ }
1041
+ }
1042
+ }
1043
+ ```
1044
+
1045
+ > ๐Ÿ“– [Cline MCP Documentation](https://docs.cline.bot/mcp/mcp-overview#mcp-overview) | [Cline MCP Marketplace](https://cline.bot/mcp-marketplace)
1046
+
1047
+ </details>
1048
+
1049
+ <details>
1050
+ <summary><strong>Python Clients (Agno, Official MCP SDK)</strong></summary>
1051
+
1052
+ #### Remote (HTTP) with Agno
1053
+
1054
+ ```python
1055
+ import asyncio
1056
+ import os
1057
+ from agno.agent import Agent
1058
+ from agno.tools.mcp import MCPTools, StreamableHTTPClientParams
1059
+
1060
+ # Get access token from environment
1061
+ token = os.environ.get('IBMI_MCP_ACCESS_TOKEN')
1062
+ if not token:
1063
+ raise ValueError("IBMI_MCP_ACCESS_TOKEN not set")
1064
+
1065
+ url = "http://localhost:3010/mcp"
1066
+ server_params = StreamableHTTPClientParams(
1067
+ url=url,
1068
+ headers={"Authorization": f"Bearer {token}"}
1069
+ )
1070
+
1071
+ async def main():
1072
+ async with MCPTools(
1073
+ url=url,
1074
+ server_params=server_params,
1075
+ transport="streamable-http"
1076
+ ) as tools:
1077
+ # List available tools
1078
+ result = await tools.session.list_tools()
1079
+ print(f"Available tools: {[t.name for t in result.tools]}")
1080
+
1081
+ # Create agent
1082
+ agent = Agent(
1083
+ model="openai:gpt-4o", # or your preferred model
1084
+ tools=[tools],
1085
+ name="ibmi-agent",
1086
+ show_tool_calls=True
1087
+ )
1088
+
1089
+ # Run query
1090
+ await agent.aprint_response("What is the system status?")
1091
+
1092
+ if __name__ == "__main__":
1093
+ asyncio.run(main())
1094
+ ```
1095
+
1096
+ #### Remote (HTTP) with Official MCP SDK
1097
+
1098
+ ```python
1099
+ import asyncio
1100
+ import os
1101
+ from mcp import ClientSession
1102
+ from mcp.client.streamable_http import streamablehttp_client
1103
+
1104
+ async def main():
1105
+ token = os.environ.get('IBMI_MCP_ACCESS_TOKEN')
1106
+ if not token:
1107
+ raise ValueError("IBMI_MCP_ACCESS_TOKEN not set")
1108
+
1109
+ headers = {"Authorization": f"Bearer {token}"}
1110
+
1111
+ async with streamablehttp_client(
1112
+ "http://localhost:3010/mcp",
1113
+ headers=headers
1114
+ ) as (read_stream, write_stream, _):
1115
+ async with ClientSession(read_stream, write_stream) as session:
1116
+ await session.initialize()
1117
+
1118
+ # List tools
1119
+ tools = await session.list_tools()
1120
+ print(f"Tools: {[t.name for t in tools.tools]}")
1121
+
1122
+ # Execute a tool
1123
+ result = await session.call_tool("system_status", {})
1124
+ print(result)
1125
+
1126
+ if __name__ == "__main__":
1127
+ asyncio.run(main())
1128
+ ```
1129
+
1130
+ > ๐Ÿ“– [MCP Python SDK](https://github.com/modelcontextprotocol/python-sdk) | [Agno Framework](https://github.com/agno-agi/agno)
1131
+
1132
+ </details>
1133
+
1134
+ ---
1135
+
1136
+ ## ๐Ÿงฉ SQL Tool Configuration
1137
+
1138
+ The primary way to configure tools used by this MCP server is through `tools.yaml` files (see `tools/` for examples). There are 3 main sections to each yaml file: `sources`, `tools`, and `toolsets`. Below is a breakdown of each section.
1139
+
1140
+ ### Sources
1141
+
1142
+ The sources section of your `tools.yaml` defines the data sources the MCP server has access to:
1143
+
1144
+ ```yaml
1145
+ sources:
1146
+ ibmi-system:
1147
+ host: ${DB2i_HOST}
1148
+ user: ${DB2i_USER}
1149
+ password: ${DB2i_PASS}
1150
+ port: 8076
1151
+ ignore-unauthorized: true
1152
+ ```
1153
+
1154
+ > [!NOTE]
1155
+ > The environment variables `DB2i_HOST`, `DB2i_USER`, `DB2i_PASS`, and `DB2i_PORT` can be set in the server `.env` file. See [Configuration](#๏ธ-configuration) for all available settings.
1156
+
1157
+ ### Tools
1158
+
1159
+ The tools section of your `tools.yaml` defines the actions your agent can take: what kind of tool it is, which source(s) it affects, what parameters it uses, etc.
1160
+
1161
+ ```yaml
1162
+ tools:
1163
+ system_status:
1164
+ source: ibmi-system
1165
+ description: "Overall system performance statistics with CPU, memory, and I/O metrics"
1166
+ parameters: []
1167
+ statement: |
1168
+ SELECT * FROM TABLE(QSYS2.SYSTEM_STATUS(RESET_STATISTICS=>'YES',DETAILED_INFO=>'ALL')) X
1169
+ ```
1170
+
1171
+ ### Toolsets
1172
+
1173
+ The toolsets section of your `tools.yaml` allows you to define groups of tools that you want to be able to load together. This can be useful for defining different sets for different agents or different applications.
1174
+
1175
+ ```yaml
1176
+ toolsets:
1177
+ performance:
1178
+ tools:
1179
+ - system_status
1180
+ - system_activity
1181
+ - remote_connections
1182
+ - memory_pools
1183
+ - temp_storage_buckets
1184
+ - unnamed_temp_storage
1185
+ - http_server
1186
+ - system_values
1187
+ - collection_services
1188
+ - collection_categories
1189
+ - active_job_info
1190
+ ```
1191
+
1192
+ > [!TIP]
1193
+ > **Advanced Tool Configuration:** For detailed documentation on creating custom SQL tools, parameter validation, advanced queries, and more, see [tools/README.md](../tools/README.md).
1194
+
1195
+ ---
1196
+
1197
+ ## ๐Ÿค– IBM i Agents
1198
+
1199
+ IBM i Agents are specialized components designed to interact with the IBM i system, providing capabilities such as monitoring, management, and automation.
1200
+
1201
+ ### Key Features
1202
+ - **Integration with IBM i:** Seamless integration with IBM i system APIs and tools.
1203
+ - **Modular Architecture:** Easily extendable and customizable to fit specific use cases.
1204
+ - **Real-time Monitoring:** Continuous monitoring of system performance and health.
1205
+
1206
+ ### Getting Started
1207
+
1208
+ Navigate to the `agents` directory and follow the setup instructions in the [README](../agents/README.md). This includes details on configuration, running agents, and examples. Most agent examples require the MCP server to be running in HTTP mode. Read the docs for each agent example for details.
1209
+
1210
+
1211
+
1212
+
1213
+
1214
+ ## โš™๏ธ Configuration
1215
+
1216
+ The server is configured using environment variables, typically set in a `.env` file at the project root. Configuration is organized into logical groups for easier management.
1217
+
1218
+ **Quick Start:**
1219
+ ```bash
1220
+ cp .env.example .env
1221
+ code .env # Edit with your settings
1222
+ ```
1223
+
1224
+ ---
1225
+
1226
+ <details>
1227
+ <summary><strong>๐Ÿ–ฅ๏ธ MCP Server Settings</strong></summary>
1228
+
1229
+ Core server configuration including server identity, transport mode, and logging.
1230
+
1231
+ | Variable | Description | Default | Required |
1232
+ |----------|-------------|---------|----------|
1233
+ | `MCP_SERVER_NAME` | Server name identifier for MCP protocol | Package name from `package.json` | No |
1234
+ | `MCP_SERVER_VERSION` | Server version for MCP protocol | Version from `package.json` | No |
1235
+ | `MCP_TRANSPORT_TYPE` | Transport protocol: `stdio` (local) or `http` (remote) | `stdio` | No |
1236
+ | `MCP_LOG_LEVEL` | Logging verbosity: `error`, `warn`, `info`, `debug` | `debug` | No |
1237
+ | `LOGS_DIR` | Directory for log files (relative to project root) | `logs` | No |
1238
+ | `NODE_ENV` | Node environment: `development`, `production`, `test` | `development` | No |
1239
+
1240
+ **Examples:**
1241
+ ```bash
1242
+ # Development with verbose logging
1243
+ MCP_SERVER_NAME=ibmi-mcp-dev
1244
+ MCP_TRANSPORT_TYPE=http
1245
+ MCP_LOG_LEVEL=debug
1246
+ NODE_ENV=development
1247
+
1248
+ # Production with minimal logging
1249
+ MCP_SERVER_NAME=ibmi-mcp-prod
1250
+ MCP_TRANSPORT_TYPE=stdio
1251
+ MCP_LOG_LEVEL=warn
1252
+ NODE_ENV=production
1253
+ ```
1254
+
1255
+ </details>
1256
+
1257
+ <details>
1258
+ <summary><strong>๐ŸŒ HTTP Transport Settings</strong></summary>
1259
+
1260
+ Configuration for HTTP transport mode, including network settings, session management, and CORS.
1261
+
1262
+ | Variable | Description | Default | Required |
1263
+ |----------|-------------|---------|----------|
1264
+ | `MCP_HTTP_PORT` | HTTP server port | `3010` | No |
1265
+ | `MCP_HTTP_HOST` | HTTP server bind address | `127.0.0.1` | No |
1266
+ | `MCP_HTTP_ENDPOINT_PATH` | MCP endpoint path | `/mcp` | No |
1267
+ | `MCP_SESSION_MODE` | Session handling: `stateless`, `stateful`, or `auto` | `auto` | No |
1268
+ | `MCP_STATEFUL_SESSION_STALE_TIMEOUT_MS` | Timeout for idle stateful sessions (milliseconds) | `1800000` (30 min) | No |
1269
+ | `MCP_HTTP_MAX_PORT_RETRIES` | Max attempts to find available port if default is in use | `15` | No |
1270
+ | `MCP_HTTP_PORT_RETRY_DELAY_MS` | Delay between port retry attempts (milliseconds) | `50` | No |
1271
+ | `MCP_ALLOWED_ORIGINS` | Comma-separated CORS allowed origins | None (all origins blocked) | No |
1272
+
1273
+ **Session Modes:**
1274
+ - **`auto`**: Automatically detects client capabilities and uses the best session mode
1275
+ - **`stateful`**: Maintains persistent sessions with connection state (best for long-running interactions)
1276
+ - **`stateless`**: Each request is independent (best for load balancing and horizontal scaling)
1277
+
1278
+ **Examples:**
1279
+ ```bash
1280
+ # Development server with CORS for local web clients
1281
+ MCP_HTTP_PORT=3010
1282
+ MCP_HTTP_HOST=0.0.0.0 # Listen on all interfaces
1283
+ MCP_SESSION_MODE=auto
1284
+ MCP_ALLOWED_ORIGINS=http://localhost:3000,http://localhost:5173
1285
+
1286
+ # Production server with strict security
1287
+ MCP_HTTP_PORT=443
1288
+ MCP_HTTP_HOST=0.0.0.0
1289
+ MCP_SESSION_MODE=stateful
1290
+ MCP_ALLOWED_ORIGINS=https://app.example.com,https://dashboard.example.com
1291
+ MCP_STATEFUL_SESSION_STALE_TIMEOUT_MS=3600000 # 1 hour
1292
+ ```
1293
+
1294
+ </details>
1295
+
1296
+ <details>
1297
+ <summary><strong>๐Ÿ” Authentication & Authorization</strong></summary>
1298
+
1299
+ Security configuration for protecting the MCP server and authenticating clients.
1300
+
1301
+ ### General Authentication
1302
+
1303
+ | Variable | Description | Default | Required |
1304
+ |----------|-------------|---------|----------|
1305
+ | `MCP_AUTH_MODE` | Authentication mode: `none`, `jwt`, `oauth`, `ibmi` | `none` | No |
1306
+
1307
+ ### JWT Authentication
1308
+
1309
+ Required when `MCP_AUTH_MODE=jwt`.
1310
+
1311
+ | Variable | Description | Default | Required |
1312
+ |----------|-------------|---------|----------|
1313
+ | `MCP_AUTH_SECRET_KEY` | Secret key for signing/verifying JWT tokens (min 32 characters) | None | โœ… Yes (for JWT mode) |
1314
+
1315
+ ### OAuth Authentication
1316
+
1317
+ Required when `MCP_AUTH_MODE=oauth`.
1318
+
1319
+ | Variable | Description | Default | Required |
1320
+ |----------|-------------|---------|----------|
1321
+ | `OAUTH_ISSUER_URL` | OAuth authorization server issuer URL | None | โœ… Yes (for OAuth mode) |
1322
+ | `OAUTH_JWKS_URI` | OAuth JWKS endpoint for public key verification | None | No |
1323
+ | `OAUTH_AUDIENCE` | Expected audience identifier for this MCP server | None | โœ… Yes (for OAuth mode) |
1324
+
1325
+ ### IBM i HTTP Authentication
1326
+
1327
+ Required when `MCP_AUTH_MODE=ibmi`. See [IBM i HTTP Authentication](#ibm-i-http-authentication-beta) for detailed setup.
1328
+
1329
+ | Variable | Description | Default | Required |
1330
+ |----------|-------------|---------|----------|
1331
+ | `IBMI_HTTP_AUTH_ENABLED` | Enable IBM i authentication endpoints | `false` | โœ… Yes (for IBM i mode) |
1332
+ | `IBMI_AUTH_ALLOW_HTTP` | Allow HTTP (non-HTTPS) authentication requests | `false` | No |
1333
+ | `IBMI_AUTH_TOKEN_EXPIRY_SECONDS` | Token lifetime in seconds | `3600` (1 hour) | No |
1334
+ | `IBMI_AUTH_CLEANUP_INTERVAL_SECONDS` | How often to clean up expired tokens (seconds) | `300` (5 minutes) | No |
1335
+ | `IBMI_AUTH_MAX_CONCURRENT_SESSIONS` | Maximum concurrent authenticated sessions | `100` | No |
1336
+ | `IBMI_AUTH_PRIVATE_KEY_PATH` | Path to RSA private key for encryption | None | โœ… Yes (for IBM i mode) |
1337
+ | `IBMI_AUTH_PUBLIC_KEY_PATH` | Path to RSA public key for encryption | None | โœ… Yes (for IBM i mode) |
1338
+ | `IBMI_AUTH_KEY_ID` | Identifier for the RSA keypair | None | โœ… Yes (for IBM i mode) |
1339
+
1340
+ **Examples:**
1341
+ ```bash
1342
+ # No authentication (development only)
1343
+ MCP_AUTH_MODE=none
1344
+
1345
+ # JWT authentication
1346
+ MCP_AUTH_MODE=jwt
1347
+ MCP_AUTH_SECRET_KEY="your-very-secret-key-at-least-32-characters-long"
1348
+
1349
+ # OAuth authentication
1350
+ MCP_AUTH_MODE=oauth
1351
+ OAUTH_ISSUER_URL=https://auth.example.com
1352
+ OAUTH_AUDIENCE=https://api.example.com/mcp
1353
+ OAUTH_JWKS_URI=https://auth.example.com/.well-known/jwks.json
1354
+
1355
+ # IBM i authentication (see docs for keypair generation)
1356
+ MCP_AUTH_MODE=ibmi
1357
+ IBMI_HTTP_AUTH_ENABLED=true
1358
+ IBMI_AUTH_KEY_ID=production
1359
+ IBMI_AUTH_PRIVATE_KEY_PATH=secrets/private.pem
1360
+ IBMI_AUTH_PUBLIC_KEY_PATH=secrets/public.pem
1361
+ IBMI_AUTH_ALLOW_HTTP=false # HTTPS only in production
1362
+ IBMI_AUTH_TOKEN_EXPIRY_SECONDS=7200 # 2 hours
1363
+ ```
1364
+
1365
+ **โš ๏ธ Security Notes:**
1366
+ - **Never** use `MCP_AUTH_MODE=none` in production
1367
+ - **Always** use `IBMI_AUTH_ALLOW_HTTP=false` in production (requires HTTPS)
1368
+ - Generate strong secret keys (32+ characters) for JWT mode
1369
+ - Rotate keys regularly for enhanced security
1370
+
1371
+ </details>
1372
+
1373
+ <details>
1374
+ <summary><strong>๐Ÿ—„๏ธ IBM i Database Connection</strong></summary>
1375
+
1376
+ Configuration for connecting to IBM i Db2 for i databases via Mapepire.
1377
+
1378
+ | Variable | Description | Default | Required |
1379
+ |----------|-------------|---------|----------|
1380
+ | `DB2i_HOST` | IBM i system hostname or IP address | None | โœ… Yes (for SQL tools) |
1381
+ | `DB2i_USER` | IBM i user profile for database connections | None | โœ… Yes (for SQL tools) |
1382
+ | `DB2i_PASS` | Password for IBM i user profile | None | โœ… Yes (for SQL tools) |
1383
+ | `DB2i_PORT` | Mapepire daemon/gateway port | `8076` | No |
1384
+ | `DB2i_IGNORE_UNAUTHORIZED` | Skip TLS certificate verification (for self-signed certs) | `true` | No |
1385
+
1386
+ **Connection Flow:**
1387
+ 1. Server connects to Mapepire daemon/gateway at `DB2i_HOST:DB2i_PORT`
1388
+ 2. Authenticates using `DB2i_USER` and `DB2i_PASS`
1389
+ 3. Executes SQL tools through authenticated connection pool
1390
+
1391
+ **Examples:**
1392
+ ```bash
1393
+ # Development connection with self-signed certs
1394
+ DB2i_HOST=ibmi-dev.example.com
1395
+ DB2i_USER=DEVUSER
1396
+ DB2i_PASS=devpassword
1397
+ DB2i_PORT=8076
1398
+ DB2i_IGNORE_UNAUTHORIZED=true
1399
+
1400
+ # Production connection with verified SSL
1401
+ DB2i_HOST=ibmi-prod.example.com
1402
+ DB2i_USER=PRODUSER
1403
+ DB2i_PASS=strongProductionPassword123
1404
+ DB2i_PORT=8076
1405
+ DB2i_IGNORE_UNAUTHORIZED=false # Require valid SSL cert
1406
+
1407
+ # Connecting to Mapepire gateway
1408
+ DB2i_HOST=mapepire-gateway.example.com
1409
+ DB2i_USER=APIUSER
1410
+ DB2i_PASS=apiPassword456
1411
+ DB2i_PORT=443 # Gateway on HTTPS
1412
+ DB2i_IGNORE_UNAUTHORIZED=false
1413
+ ```
1414
+
1415
+ **โš ๏ธ Security Notes:**
1416
+ - Store credentials securely (use secrets management in production)
1417
+ - Use read-only accounts when possible
1418
+ - Set `DB2i_IGNORE_UNAUTHORIZED=false` with valid SSL certificates in production
1419
+ - Consider using IBM i authentication mode for per-user connection pooling
1420
+
1421
+ </details>
1422
+
1423
+ <details>
1424
+ <summary><strong>๐Ÿงฉ SQL YAML Tool Configuration</strong></summary>
1425
+
1426
+ Settings for loading and managing SQL tools defined in YAML configuration files. See [Tools Documentation](../tools/README.md) for YAML tool development.
1427
+
1428
+ ### Tool Loading
1429
+
1430
+ | Variable | Description | Default | Required |
1431
+ |----------|-------------|---------|----------|
1432
+ | `TOOLS_YAML_PATH` | Path to YAML tool configurations (file, directory, or glob) | None | No |
1433
+ | `SELECTED_TOOLSETS` | Comma-separated list of toolsets to load (filters available tools) | None (load all) | No |
1434
+ | `YAML_AUTO_RELOAD` | Automatically reload tools when YAML files change | `true` | No |
1435
+
1436
+ ### Configuration Merging
1437
+
1438
+ When loading multiple YAML files, these settings control merge behavior:
1439
+
1440
+ | Variable | Description | Default | Required |
1441
+ |----------|-------------|---------|----------|
1442
+ | `YAML_MERGE_ARRAYS` | Merge arrays from multiple files (`true`) or replace them (`false`) | `true` | No |
1443
+ | `YAML_ALLOW_DUPLICATE_TOOLS` | Allow duplicate tool names across files | `false` | No |
1444
+ | `YAML_ALLOW_DUPLICATE_SOURCES` | Allow duplicate source names across files | `false` | No |
1445
+ | `YAML_VALIDATE_MERGED` | Validate merged configuration before loading tools | `true` | No |
1446
+
1447
+ **Path Resolution:**
1448
+ - **File**: `TOOLS_YAML_PATH=tools/performance.yaml`
1449
+ - **Directory**: `TOOLS_YAML_PATH=tools/` (loads all .yaml/.yml files)
1450
+ - **Glob pattern**: `TOOLS_YAML_PATH=tools/**/*.yaml`
1451
+ - **Multiple sources**: Use CLI `--tools` to override at runtime
1452
+
1453
+ **Examples:**
1454
+ ```bash
1455
+ # Load all tools from a directory
1456
+ TOOLS_YAML_PATH=tools/
1457
+ YAML_AUTO_RELOAD=true # Hot reload on file changes
1458
+
1459
+ # Load specific tools file
1460
+ TOOLS_YAML_PATH=tools/performance-tools.yaml
1461
+ SELECTED_TOOLSETS=monitoring,diagnostics
1462
+
1463
+ # Advanced merging (multiple config sources)
1464
+ TOOLS_YAML_PATH=tools/
1465
+ YAML_MERGE_ARRAYS=true # Combine toolsets from multiple files
1466
+ YAML_ALLOW_DUPLICATE_TOOLS=false # Enforce unique tool names
1467
+ YAML_VALIDATE_MERGED=true # Validate after merging
1468
+
1469
+ # Production: disable hot reload
1470
+ TOOLS_YAML_PATH=/opt/mcp-tools/production.yaml
1471
+ YAML_AUTO_RELOAD=false
1472
+ ```
1473
+
1474
+ **CLI Override:**
1475
+ ```bash
1476
+ # Override TOOLS_YAML_PATH at runtime
1477
+ npx ibmi-mcp-server --tools ./my-custom-tools
1478
+
1479
+ # Load specific toolsets only
1480
+ npx ibmi-mcp-server --toolsets performance,security
1481
+ ```
1482
+
1483
+ </details>
1484
+
1485
+ <details>
1486
+ <summary><strong>๐Ÿ“Š OpenTelemetry (Observability)</strong></summary>
1487
+
1488
+ Configuration for distributed tracing and metrics using OpenTelemetry.
1489
+
1490
+ | Variable | Description | Default | Required |
1491
+ |----------|-------------|---------|----------|
1492
+ | `OTEL_ENABLED` | Enable OpenTelemetry instrumentation | `false` | No |
1493
+ | `OTEL_SERVICE_NAME` | Service name for telemetry data | `MCP_SERVER_NAME` or package name | No |
1494
+ | `OTEL_SERVICE_VERSION` | Service version for telemetry data | `MCP_SERVER_VERSION` or package version | No |
1495
+ | `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT` | OTLP endpoint for trace export | None (logs to file) | No |
1496
+ | `OTEL_EXPORTER_OTLP_METRICS_ENDPOINT` | OTLP endpoint for metrics export | None (not exported) | No |
1497
+ | `OTEL_TRACES_SAMPLER_ARG` | Trace sampling ratio (0.0 to 1.0, where 1.0 = sample all) | `1.0` (100%) | No |
1498
+ | `OTEL_LOG_LEVEL` | OTel internal diagnostic log level | `INFO` | No |
1499
+
1500
+ **Supported OTEL_LOG_LEVEL values:** `NONE`, `ERROR`, `WARN`, `INFO`, `DEBUG`, `VERBOSE`, `ALL`
1501
+
1502
+ **Examples:**
1503
+ ```bash
1504
+ # Development: local file logging only
1505
+ OTEL_ENABLED=true
1506
+ OTEL_SERVICE_NAME=ibmi-mcp-dev
1507
+ OTEL_LOG_LEVEL=DEBUG
1508
+ # Traces written to logs/traces/ directory
1509
+
1510
+ # Production: export to Jaeger
1511
+ OTEL_ENABLED=true
1512
+ OTEL_SERVICE_NAME=ibmi-mcp-prod
1513
+ OTEL_SERVICE_VERSION=1.9.1
1514
+ OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=http://jaeger:4318/v1/traces
1515
+ OTEL_EXPORTER_OTLP_METRICS_ENDPOINT=http://jaeger:4318/v1/metrics
1516
+ OTEL_TRACES_SAMPLER_ARG=0.1 # Sample 10% of traces
1517
+ OTEL_LOG_LEVEL=WARN
1518
+
1519
+ # Production: export to cloud provider
1520
+ OTEL_ENABLED=true
1521
+ OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=https://otlp.example.com/v1/traces
1522
+ OTEL_EXPORTER_OTLP_METRICS_ENDPOINT=https://otlp.example.com/v1/metrics
1523
+ OTEL_TRACES_SAMPLER_ARG=1.0 # Sample all traces
1524
+ ```
1525
+
1526
+ **Instrumentation Coverage:**
1527
+ - All MCP tool executions
1528
+ - HTTP requests and responses
1529
+ - Database queries (SQL tools)
1530
+ - Authentication flows
1531
+ - Custom spans for critical operations
1532
+
1533
+ </details>
1534
+
1535
+ <details>
1536
+ <summary><strong>๐Ÿ”Œ OAuth Proxy (Advanced)</strong></summary>
1537
+
1538
+ Configuration for OAuth proxy endpoints (advanced use cases).
1539
+
1540
+ | Variable | Description | Default | Required |
1541
+ |----------|-------------|---------|----------|
1542
+ | `OAUTH_PROXY_AUTHORIZATION_URL` | OAuth authorization endpoint URL | None | No |
1543
+ | `OAUTH_PROXY_TOKEN_URL` | OAuth token endpoint URL | None | No |
1544
+ | `OAUTH_PROXY_REVOCATION_URL` | OAuth token revocation endpoint URL | None | No |
1545
+ | `OAUTH_PROXY_ISSUER_URL` | OAuth issuer URL for proxy | None | No |
1546
+ | `OAUTH_PROXY_SERVICE_DOCUMENTATION_URL` | Service documentation URL | None | No |
1547
+ | `OAUTH_PROXY_DEFAULT_CLIENT_REDIRECT_URIS` | Comma-separated default redirect URIs | None | No |
1548
+
1549
+ **Example:**
1550
+ ```bash
1551
+ OAUTH_PROXY_AUTHORIZATION_URL=https://auth.example.com/oauth/authorize
1552
+ OAUTH_PROXY_TOKEN_URL=https://auth.example.com/oauth/token
1553
+ OAUTH_PROXY_REVOCATION_URL=https://auth.example.com/oauth/revoke
1554
+ OAUTH_PROXY_ISSUER_URL=https://auth.example.com
1555
+ OAUTH_PROXY_SERVICE_DOCUMENTATION_URL=https://docs.example.com/oauth
1556
+ OAUTH_PROXY_DEFAULT_CLIENT_REDIRECT_URIS=http://localhost:3000/callback,https://app.example.com/callback
1557
+ ```
1558
+
1559
+ > **Note:** OAuth proxy features are for advanced integration scenarios. Most users should use standard OAuth authentication via `MCP_AUTH_MODE=oauth`.
1560
+
1561
+ </details>
1562
+
1563
+ ---
1564
+
1565
+ ### Configuration Best Practices
1566
+
1567
+ **Development:**
1568
+ ```bash
1569
+ # Recommended development .env
1570
+ MCP_TRANSPORT_TYPE=http
1571
+ MCP_HTTP_PORT=3010
1572
+ MCP_SESSION_MODE=auto
1573
+ MCP_LOG_LEVEL=debug
1574
+ MCP_AUTH_MODE=none # Or ibmi with allow HTTP
1575
+ NODE_ENV=development
1576
+
1577
+ DB2i_HOST=ibmi-dev.local
1578
+ DB2i_USER=DEVUSER
1579
+ DB2i_PASS=devpass
1580
+ DB2i_IGNORE_UNAUTHORIZED=true
1581
+
1582
+ TOOLS_YAML_PATH=tools/
1583
+ YAML_AUTO_RELOAD=true
1584
+ OTEL_ENABLED=true
1585
+ ```
1586
+
1587
+ **Production:**
1588
+ ```bash
1589
+ # Recommended production .env
1590
+ MCP_TRANSPORT_TYPE=http
1591
+ MCP_HTTP_PORT=3010
1592
+ MCP_SESSION_MODE=auto
1593
+ MCP_LOG_LEVEL=warn
1594
+ MCP_AUTH_MODE=ibmi # Or jwt/oauth
1595
+ NODE_ENV=production
1596
+
1597
+ DB2i_HOST=ibmi-prod.example.com
1598
+ DB2i_USER=PRODUSER
1599
+ DB2i_PASS=${SECURE_PASSWORD_FROM_VAULT}
1600
+ DB2i_IGNORE_UNAUTHORIZED=false # Require valid SSL
1601
+
1602
+ TOOLS_YAML_PATH=/opt/mcp-tools/production.yaml
1603
+ YAML_AUTO_RELOAD=false
1604
+ YAML_VALIDATE_MERGED=true
1605
+
1606
+ IBMI_HTTP_AUTH_ENABLED=true
1607
+ IBMI_AUTH_ALLOW_HTTP=false # HTTPS only
1608
+ IBMI_AUTH_PRIVATE_KEY_PATH=/opt/secrets/private.pem
1609
+ IBMI_AUTH_PUBLIC_KEY_PATH=/opt/secrets/public.pem
1610
+
1611
+ OTEL_ENABLED=true
1612
+ OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=https://otlp.example.com/v1/traces
1613
+ ```
1614
+
1615
+ **Security Checklist:**
1616
+ - โœ… Never commit `.env` files to version control
1617
+ - โœ… Use secrets management (Vault, AWS Secrets Manager, etc.) in production
1618
+ - โœ… Rotate credentials and keys regularly
1619
+ - โœ… Use HTTPS/TLS in production (`IBMI_AUTH_ALLOW_HTTP=false`)
1620
+ - โœ… Enable authentication (`MCP_AUTH_MODE != none`)
1621
+ - โœ… Use strong passwords (12+ characters, mixed case, numbers, symbols)
1622
+ - โœ… Restrict `MCP_ALLOWED_ORIGINS` to known domains
1623
+ - โœ… Set appropriate `IBMI_AUTH_MAX_CONCURRENT_SESSIONS` limits
1624
+
1625
+ ## ๐Ÿ” IBM i HTTP Authentication (Beta)
1626
+
1627
+ The server supports IBM i HTTP authentication that allows clients to obtain access tokens for authenticated SQL tool execution. This enables per-user connection pooling and secure access to IBM i resources.
1628
+
1629
+ ### Authentication Flow
1630
+
1631
+ 1. **Client Authentication**: Clients authenticate with IBM i credentials via HTTP Basic Auth
1632
+ 2. **Token Generation**: Server creates a secure Bearer token and establishes a dedicated connection pool
1633
+ 3. **Tool Execution**: Subsequent tool calls use the Bearer token for authenticated execution
1634
+ 4. **Pool Management**: Each token maintains its own connection pool for isolation and security
1635
+
1636
+ ### Configuration
1637
+
1638
+ To enable IBM i HTTP authentication, we need to set up Encryption keys and configure the server environment. To protect IBM i credentials during transmission, the authentication flow uses RSA and AES encryption. You need to generate an RSA keypair for the server:
1639
+
1640
+ ```bash
1641
+ mkdir -p secrets
1642
+ openssl genpkey -algorithm RSA -out secrets/private.pem -pkeyopt rsa_keygen_bits:2048
1643
+ openssl rsa -pubout -in secrets/private.pem -out secrets/public.pem
1644
+ ```
1645
+
1646
+ Create or update your `.env` file with the following settings:
1647
+
1648
+ ```ini
1649
+ # Enable IBM i authentication system
1650
+ IBMI_HTTP_AUTH_ENABLED=true
1651
+ MCP_AUTH_MODE=ibmi
1652
+
1653
+ # IBM i authentication settings
1654
+ IBMI_AUTH_KEY_ID=development
1655
+ IBMI_AUTH_PRIVATE_KEY_PATH=secrets/private.pem
1656
+ IBMI_AUTH_PUBLIC_KEY_PATH=secrets/public.pem
1657
+
1658
+ # Security settings
1659
+ IBMI_AUTH_ALLOW_HTTP=true # Development only - use HTTPS in production
1660
+ IBMI_AUTH_TOKEN_EXPIRY_SECONDS=3600 # Token lifetime (1 hour)
1661
+
1662
+ # Resource management
1663
+ IBMI_AUTH_MAX_CONCURRENT_SESSIONS=100
1664
+ IBMI_AUTH_CLEANUP_INTERVAL_SECONDS=300
1665
+
1666
+ # IBM i connection details
1667
+ DB2i_HOST=your-ibmi-host
1668
+ DB2i_USER=your-username
1669
+ DB2i_PASS=your-password
1670
+ ```
1671
+
1672
+
1673
+ ### Getting Access Tokens
1674
+
1675
+ #### Option 1: Using the Token Script (Recommended)
1676
+
1677
+ Use the included `get-access-token.js` script to obtain authentication tokens:
1678
+
1679
+ ```bash
1680
+ # Using credentials from .env file
1681
+ node get-access-token.js --verbose
1682
+
1683
+ # Using CLI arguments (overrides .env)
1684
+ node get-access-token.js --user myuser --password mypass --host my-ibmi-host
1685
+
1686
+ # Quiet mode for shell evaluation
1687
+ eval $(node get-access-token.js --quiet)
1688
+ echo $IBMI_MCP_ACCESS_TOKEN
1689
+ ```
1690
+
1691
+ The script automatically:
1692
+
1693
+ - Loads IBM i credentials from `.env` with CLI fallback
1694
+ - Fetches the server's public key
1695
+ - Encrypts credentials client-side
1696
+ - Requests an access token
1697
+ - Sets `IBMI_MCP_ACCESS_TOKEN` environment variable
1698
+ - Provides copy-paste export commands
1699
+
1700
+ #### Sequence Overview
1701
+
1702
+ ```mermaid
1703
+ sequenceDiagram
1704
+ participant CLI as Client CLI
1705
+ participant Auth as MCP Server (/api/v1/auth)
1706
+ participant IBM as IBM i
1707
+
1708
+ CLI->>Auth: GET /api/v1/auth/public-key
1709
+ Auth-->>CLI: { keyId, publicKey }
1710
+
1711
+ CLI->>CLI: Generate AES-256-GCM session key + IV
1712
+ CLI->>CLI: Encrypt credentials + request body with session key
1713
+ CLI->>CLI: Encrypt session key with server public key (RSA-OAEP)
1714
+
1715
+ CLI->>Auth: POST /api/v1/auth { keyId, encryptedSessionKey, iv, authTag, ciphertext }
1716
+ Auth->>Auth: Look up keyId, decrypt session key with private key
1717
+ Auth->>Auth: Decrypt ciphertext, validate GCM tag, validate payload
1718
+
1719
+ Auth->>IBM: Authenticate against IBM i with decrypted credentials
1720
+ IBM-->>Auth: Success/Failure
1721
+
1722
+ Auth->>Auth: Generate access token, provision pool session
1723
+ Auth-->>CLI: 201 JSON { access_token, expires_in, ... }
1724
+ ```
1725
+
1726
+ ### Client Integration
1727
+
1728
+ Once you have a token, use it in your MCP client to authenticate requests:
1729
+
1730
+ ```python
1731
+ import asyncio
1732
+ import os
1733
+ from mcp import ClientSession
1734
+ from mcp.client.streamable_http import streamablehttp_client
1735
+
1736
+ async def main():
1737
+ # Get the access token from environment
1738
+ token = os.environ.get('IBMI_MCP_ACCESS_TOKEN')
1739
+ if not token:
1740
+ raise ValueError("IBMI_MCP_ACCESS_TOKEN environment variable not set")
1741
+
1742
+ # Set up authentication headers
1743
+ headers = {"Authorization": f"Bearer {token}"}
1744
+
1745
+ # Connect to the IBM i MCP server with authentication
1746
+ async with streamablehttp_client(
1747
+ "http://localhost:3010/mcp",
1748
+ headers=headers
1749
+ ) as (read_stream, write_stream, _):
1750
+ # Create a session using the authenticated streams
1751
+ async with ClientSession(read_stream, write_stream) as session:
1752
+ # Initialize the connection
1753
+ await session.initialize()
1754
+
1755
+ # List available tools (now authenticated with your IBM i credentials)
1756
+ tools = await session.list_tools()
1757
+ print(f"Available tools: {[tool.name for tool in tools.tools]}")
1758
+
1759
+ # Execute a tool with authenticated IBM i access
1760
+ result = await session.call_tool("system_status", {})
1761
+ print(f"System status result: {result}")
1762
+
1763
+ if __name__ == "__main__":
1764
+ asyncio.run(main())
1765
+ ```
1766
+
1767
+ ### Security Considerations
1768
+
1769
+ **Development Environment:**
1770
+
1771
+ - `IBMI_AUTH_ALLOW_HTTP=true` allows HTTP for testing
1772
+ - Use localhost/trusted networks only
1773
+ - Shorter token lifetimes for testing
1774
+
1775
+ **Production Environment:**
1776
+
1777
+ - `IBMI_AUTH_ALLOW_HTTP=false` enforces HTTPS
1778
+ - Use proper TLS certificates
1779
+ - Longer token lifetimes for stability
1780
+ - Network security and access controls
1781
+ - Monitor `IBMI_AUTH_MAX_CONCURRENT_SESSIONS` for resource usage
1782
+
1783
+ ### Authentication Endpoints
1784
+
1785
+ When enabled (`IBMI_HTTP_AUTH_ENABLED=true`), the server provides these endpoints:
1786
+
1787
+ | Endpoint | Method | Description |
1788
+ | -------------- | ------ | ------------------------------------------------------------ |
1789
+ | `/api/v1/auth` | POST | Authenticate with IBM i credentials and receive Bearer token |
1790
+
1791
+
1792
+
1793
+ ## ๐Ÿ› ๏ธ Running the Server (Development)
1794
+
1795
+ For development and contributions, you can build and run the server from source.
1796
+
1797
+ ### Building from Source
1798
+
1799
+ **1. Clone and Install:**
6
1800
 
7
1801
  ```bash
8
- # Install dependencies
1802
+ git clone https://github.com/IBM/ibmi-mcp-server.git
1803
+ cd ibmi-mcp-server
9
1804
  npm install
1805
+ ```
10
1806
 
11
- # Build
1807
+ **2. Build the Project:**
1808
+
1809
+ ```bash
1810
+ # Build TypeScript to JavaScript
12
1811
  npm run build
13
1812
 
14
- # Run server (HTTP mode)
1813
+ # Or clean rebuild
1814
+ npm run rebuild
1815
+ ```
1816
+
1817
+ **3. Configure Environment:**
1818
+
1819
+ ```bash
1820
+ # Copy example configuration
1821
+ cp .env.example .env
1822
+
1823
+ # Edit with your IBM i connection details
1824
+ code .env
1825
+ ```
1826
+
1827
+ **4. Run Development Server:**
1828
+
1829
+ ```bash
1830
+ # Start in HTTP mode
15
1831
  npm run start:http
16
1832
 
17
- # Run server (stdio mode)
1833
+ # Start in stdio mode
18
1834
  npm run start:stdio
1835
+ ```
19
1836
 
20
- # Run tests
1837
+ **5. Run Tests:**
1838
+
1839
+ ```bash
1840
+ # Run all tests
21
1841
  npm test
1842
+
1843
+ # Run in watch mode
1844
+ npm run test:watch
1845
+
1846
+ # Generate coverage report
1847
+ npm run test:coverage
22
1848
  ```
23
1849
 
24
- ## Configuration
1850
+ ---
25
1851
 
26
- Create a `.env` file in the **root of the monorepo** (parent directory):
1852
+ ### Transport Modes
1853
+
1854
+ #### HTTP Transport (Recommended for Development)
1855
+
1856
+ ```bash
1857
+ # Basic HTTP server
1858
+ npm run start:http
1859
+
1860
+ # HTTP with custom tools path
1861
+ npm run start:http -- --tools ./my-configs
1862
+
1863
+ # HTTP with specific toolsets
1864
+ npm run start:http -- --toolsets performance,monitoring
1865
+ ```
1866
+
1867
+ #### Stdio Transport (for CLI tools and MCP Inspector)
27
1868
 
28
1869
  ```bash
29
- cp ../.env.example ../.env
1870
+ # Basic stdio transport
1871
+ npm run start:stdio
1872
+
1873
+ # Stdio with custom tools path
1874
+ npm run start:stdio -- --tools ./my-custom-tools
30
1875
  ```
31
1876
 
32
- The server will automatically detect configuration in:
1877
+ > Make sure that to use the absolute path for tools
33
1878
 
34
- 1. Current working directory (for production deployments)
35
- 2. Parent directory (for monorepo development)
36
- 3. Server directory (for local overrides)
1879
+ ### Session Modes (HTTP Only)
37
1880
 
38
- ## Tool Configuration
1881
+ The `MCP_SESSION_MODE` environment variable controls how the HTTP server handles client sessions:
39
1882
 
40
- By default, the server loads SQL tools from `../tools/`. Override with:
1883
+ - **`auto` (default)**: Automatically detects client capabilities and uses the best session mode
1884
+ - **`stateful`**: Maintains persistent sessions with connection state
1885
+ - **`stateless`**: Each request is independent, no session state maintained
41
1886
 
42
1887
  ```bash
43
- TOOLS_YAML_PATH=../tools npm run start:http
1888
+ # Set session mode via environment variable
1889
+ MCP_SESSION_MODE=stateful npm run start:http
1890
+
1891
+ # Or set in .env file
1892
+ echo "MCP_SESSION_MODE=stateful" >> .env
1893
+ npm run start:http
44
1894
  ```
45
1895
 
46
- Or set in your `.env` file:
1896
+ ### CLI Options
47
1897
 
48
- ```ini
49
- TOOLS_YAML_PATH=tools
1898
+ Both transport modes support these command-line options:
1899
+
1900
+ > **Note**: CLI arguments override corresponding settings in `.env` file when provided.
1901
+
1902
+ | Option | Short | Description | Example |
1903
+ | -------------------- | ----- | ----------------------------------------------------------------------------- | --------------------------------- |
1904
+ | `--tools <path>` | | Override YAML tools configuration path (overrides `TOOLS_YAML_PATH`) | `--tools ./custom-configs` |
1905
+ | `--toolsets <list>` | `-ts` | Load only specific toolsets (comma-separated) (overrides `SELECTED_TOOLSETS`) | `--toolsets performance,security` |
1906
+ | `--transport <type>` | `-t` | Force transport type (`http` or `stdio`) (overrides `MCP_TRANSPORT_TYPE`) | `--transport http` |
1907
+ | `--help` | `-h` | Show help information | `--help` |
1908
+ | `--list-toolsets` | | List available toolsets from YAML configuration | `--list-toolsets` |
1909
+
1910
+ ### Common Development Scenarios
1911
+
1912
+ **1. Standard Development Server**
1913
+
1914
+ ```bash
1915
+ npm run start:http
1916
+ # Server: http://localhost:3010/mcp
1917
+ # Tools: tools/ (from .env)
1918
+ # Session: auto-detected
1919
+ ```
1920
+
1921
+ **2. Custom Tools Path**
1922
+
1923
+ ```bash
1924
+ npm run start:http -- --tools ./my-tools
1925
+ # Server: http://localhost:3010/mcp (port from .env or default)
1926
+ # Tools: ./my-tools
1927
+ ```
1928
+
1929
+ **3. Specific Toolsets Only**
1930
+
1931
+ ```bash
1932
+ npm run start:http -- --toolsets performance,monitoring
1933
+ # Only loads tools from 'performance' and 'monitoring' toolsets
1934
+ ```
1935
+
1936
+ ### Development Tips
1937
+
1938
+ - **Hot Reloading**: Enable `YAML_AUTO_RELOAD=true` in `.env` for automatic tool configuration updates
1939
+ - **Verbose Logging**: Set `MCP_LOG_LEVEL=debug` for detailed operation logs
1940
+ - **CORS**: Configure `MCP_ALLOWED_ORIGINS` for web-based clients
1941
+ - **Authentication**: Use `MCP_AUTH_MODE=ibmi` with IBM i HTTP auth for token-based access
1942
+
1943
+ ### Troubleshooting
1944
+
1945
+ **Port Already in Use**
1946
+
1947
+ ```bash
1948
+ # Configure port in .env file
1949
+ echo "MCP_HTTP_PORT=3011" >> .env
1950
+ npm run start:http
1951
+ ```
1952
+
1953
+ **Tools Not Loading**
1954
+
1955
+ ```bash
1956
+ # Check tools path
1957
+ npm run start:http -- --tools ./tools
1958
+
1959
+ # List available toolsets first
1960
+ npm run start:http -- --list-toolsets --tools ./tools
1961
+
1962
+ # Get help
1963
+ npm run start:http -- --help
50
1964
  ```
51
1965
 
52
- ## Documentation
1966
+ ## ๐Ÿ•ต๏ธโ€โ™‚๏ธ MCP Inspector
1967
+
1968
+ The MCP Inspector is a tool for exploring and debugging the MCP server's capabilities. It provides a user-friendly interface for interacting with the server, viewing available tools, and testing queries.
1969
+
1970
+ Here are the steps to run the MCP Inspector:
1971
+
1972
+ 1. Make sure to build the server
1973
+ ```bash
1974
+ cd ibmi-mcp-server/
1975
+ npm run build
1976
+ ```
1977
+ 2. Create an `mcp.json` file:
1978
+
1979
+ ```bash
1980
+ cp template_mcp.json mcp.json
1981
+ ```
1982
+
1983
+ Fill out the connection details in `mcp.json` with your IBM i system information. You should use the same credentials as in your `.env` file:
1984
+
1985
+ ```json
1986
+ {
1987
+ "mcpServers": {
1988
+ "default-server": {
1989
+ "command": "node",
1990
+ "args": ["dist/index.js", "--transport", "stdio", "--tools", "tools"],
1991
+ "env": {
1992
+ "NODE_OPTIONS": "--no-deprecation",
1993
+ "DB2i_HOST": "<DB2i_HOST>",
1994
+ "DB2i_USER": "<DB2i_USER>",
1995
+ "DB2i_PASS": "<DB2i_PASS>",
1996
+ "DB2i_PORT": "<DB2i_PORT>"
1997
+ }
1998
+ }
1999
+ }
2000
+ }
2001
+ ```
53
2002
 
54
- See the [root README](../README.md) for complete documentation and deployment guides.
2003
+ 3. Start the MCP Inspector
2004
+ ```bash
2005
+ npm run mcp-inspector
2006
+ ```
2007
+ 4. Click on the URL displayed in the terminal to open the MCP Inspector in your web browser.
55
2008
 
56
- ## Development
2009
+ ```bash
2010
+ Starting MCP inspector...
2011
+ โš™๏ธ Proxy server listening on 127.0.0.1:6277
2012
+ ๐Ÿ”‘ Session token: EXAMPLE_TOKEN
2013
+ Use this token to authenticate requests or set DANGEROUSLY_OMIT_AUTH=true to disable auth
57
2014
 
58
- This is the main server package within the monorepo. All server development happens here.
2015
+ ๐Ÿ”— Open inspector with token pre-filled:
2016
+ http://localhost:6274/?MCP_PROXY_AUTH_TOKEN=EXAMPLE_TOKEN
59
2017
 
60
- - **Source**: `src/`
61
- - **Tests**: `tests/`
62
- - **Scripts**: `scripts/`
63
- - **Build Output**: `dist/`
2018
+ ๐Ÿ” MCP Inspector is up and running at http://127.0.0.1:6274 ๐Ÿš€
2019
+ ```
64
2020
 
65
- ### Available Scripts
2021
+ ![alt text](../docs/images/inspector.png)
66
2022
 
67
- - `npm run build` - Build the server
68
- - `npm run rebuild` - Clean and rebuild
69
- - `npm run start:http` - Start in HTTP mode
70
- - `npm run start:stdio` - Start in stdio mode
71
- - `npm test` - Run tests
72
- - `npm run test:watch` - Run tests in watch mode
73
- - `npm run test:coverage` - Run tests with coverage
74
- - `npm run lint` - Lint code
75
- - `npm run format` - Format code with Prettier
76
- - `npm run validate` - Validate tool configurations
2023
+ 5. Use the MCP Inspector to explore and test your MCP server's capabilities
2024
+ - View available tools and their parameters
2025
+ - Test queries against the server
2026
+ - Debug issues with tool execution
77
2027
 
78
- ### Architecture
2028
+ ---
79
2029
 
80
- See [CLAUDE.md](../CLAUDE.md) for architectural standards and development guidelines.
2030
+ ## Deployment
81
2031
 
82
- ## Monorepo Structure
2032
+ For production deployments with Docker, Podman, or OpenShift, see the [Deployment Guide](../deployment/README.md).
83
2033
 
84
- This server is part of a monorepo:
2034
+ ---
85
2035
 
86
- - `../tools/` - SQL tool YAML configurations
87
- - `../agents/` - Agent implementations and examples
88
- - `../apps/` - Deployment configurations (Docker, Gateway, n8n)
2036
+ ## ๐Ÿ—๏ธ Built With MCP TypeScript Template
2037
+
2038
+ This server was built using the [MCP TypeScript Template](https://github.com/cyanheads/mcp-ts-template), a production-ready foundation for building Model Context Protocol servers.
2039
+
2040
+ ### Template Features Used
2041
+
2042
+ The template provided essential infrastructure that accelerated development:
2043
+
2044
+ - **๐Ÿ”Œ Transport Layer** - Pre-built stdio and HTTP (Hono) transports with session management
2045
+ - **๐Ÿ”ญ Observability** - OpenTelemetry integration for distributed tracing and metrics
2046
+ - **๐Ÿ”’ Security** - Authentication middleware (JWT, OAuth, custom), input sanitization, rate limiting
2047
+ - **โš™๏ธ Error Handling** - Structured error categorization with `BaseErrorCode` and centralized `ErrorHandler`
2048
+ - **๐Ÿ“Š Type Safety** - TypeScript + Zod validation throughout the stack
2049
+ - **๐Ÿงช Testing Infrastructure** - Vitest integration with coverage reporting
2050
+
2051
+ ### Why This Template?
2052
+
2053
+ The MCP TypeScript Template provided a solid architectural foundation that allowed us to focus on IBM i-specific functionality rather than building MCP infrastructure from scratch. Key benefits:
2054
+
2055
+ 1. **Production-Ready Patterns**: "Logic Throws, Handler Catches" pattern ensures consistent error handling
2056
+ 2. **Modular Design**: Clear separation between core logic, handlers, and transports
2057
+ 3. **Enterprise Features**: Built-in observability, security, and performance monitoring
2058
+ 4. **Developer Experience**: Hot reloading, structured logging, and comprehensive tooling
2059
+
2060
+ ### Customizations for IBM i
2061
+
2062
+ While the template provided the foundation, we added IBM i-specific capabilities:
2063
+
2064
+ - **Mapepire Integration** - WebSocket-based Db2 for i connectivity
2065
+ - **SQL YAML Tool Configuration** - Declarative SQL tool definitions with merge capabilities
2066
+ - **IBM i HTTP Authentication** - RSA/AES encrypted credential flow with connection pooling
2067
+ - **SQL Tool Execution** - Parameterized query execution with result formatting
2068
+ - **Toolset Management** - Dynamic tool loading and filtering by toolset
2069
+
2070
+ ### Get Started with the Template
2071
+
2072
+ If you're building your own MCP server, check out the template:
2073
+
2074
+ ```bash
2075
+ # Use the template to create your own MCP server
2076
+ npx degit cyanheads/mcp-ts-template my-mcp-server
2077
+ cd my-mcp-server
2078
+ npm install
2079
+ npm run build
2080
+ ```