Skip to content

Commit 975991f

Browse files
committed
Add --agent-managed CLI Flag
Agent-Id: agent-bb8e0202-acb6-4479-940b-8cb958aa88f1 Linked-Note-Id: 5039c3be-a4e3-4fed-a279-827b12453884
1 parent e0fc0f7 commit 975991f

File tree

1 file changed

+31
-6
lines changed

1 file changed

+31
-6
lines changed

src/bin/cmd-mcp.ts

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { FilesystemStore } from "../stores/filesystem.js";
77
import { runMCPServer } from "../clients/mcp-server.js";
88
import { parseIndexSpecs } from "../stores/index-spec.js";
99
import { CompositeStoreReader } from "../stores/composite.js";
10+
import { LayeredStore } from "../stores/index.js";
1011

1112
// stdio subcommand (stdio-based MCP server for local clients like Claude Desktop)
1213
const stdioCommand = new Command("stdio")
@@ -15,32 +16,44 @@ const stdioCommand = new Command("stdio")
1516
"-i, --index <specs...>",
1617
"Index spec(s): name, path:/path, or s3://bucket/key"
1718
)
19+
.option("--agent-managed", "Enable dynamic index management (index_repo, delete_index)")
1820
.option("--search-only", "Disable list_files/read_file tools (search only)")
1921
.action(async (options) => {
2022
try {
2123
const indexSpecs: string[] | undefined = options.index;
24+
const agentManaged = options.agentManaged || !indexSpecs || indexSpecs.length === 0;
2225

2326
let store;
2427
let indexNames: string[] | undefined;
2528

2629
if (indexSpecs && indexSpecs.length > 0) {
27-
// Parse index specs and create composite store
30+
// Parse index specs
2831
const specs = parseIndexSpecs(indexSpecs);
29-
store = await CompositeStoreReader.fromSpecs(specs);
3032
indexNames = specs.map((s) => s.displayName);
33+
34+
if (agentManaged) {
35+
// Agent-managed + remote indexes: use LayeredStore
36+
const remoteStore = await CompositeStoreReader.fromSpecs(specs);
37+
store = new LayeredStore(new FilesystemStore(), remoteStore);
38+
} else {
39+
// Fixed mode: use read-only CompositeStoreReader
40+
store = await CompositeStoreReader.fromSpecs(specs);
41+
}
3142
} else {
32-
// No --index: use default store, list all indexes
43+
// No --index: use FilesystemStore (agent-managed mode)
3344
store = new FilesystemStore();
3445
// Dynamic indexing: server can start with zero indexes
3546
// Use list_indexes to see available indexes, index_repo to create new ones
3647
indexNames = undefined;
3748
}
3849

3950
// Start MCP server (writes to stdout, reads from stdin)
51+
// agentManaged: true when no -i flags (dynamic mode), false when -i flags provided (fixed mode)
4052
await runMCPServer({
4153
store,
4254
indexNames,
4355
searchOnly: options.searchOnly,
56+
agentManaged: !indexSpecs || indexSpecs.length === 0,
4457
});
4558
} catch (error) {
4659
// Write errors to stderr (stdout is for MCP protocol)
@@ -56,6 +69,7 @@ const httpCommand = new Command("http")
5669
"-i, --index <specs...>",
5770
"Index spec(s): name, path:/path, or s3://bucket/key"
5871
)
72+
.option("--agent-managed", "Enable dynamic index management (index_repo, delete_index)")
5973
.option("--port <number>", "Port to listen on", "3000")
6074
.option("--host <host>", "Host to bind to", "localhost")
6175
.option("--cors <origins>", "CORS origins (comma-separated, or '*' for any)")
@@ -68,17 +82,26 @@ const httpCommand = new Command("http")
6882
.action(async (options) => {
6983
try {
7084
const indexSpecs: string[] | undefined = options.index;
85+
const agentManaged = options.agentManaged || !indexSpecs || indexSpecs.length === 0;
7186

7287
let store;
7388
let indexNames: string[] | undefined;
7489

7590
if (indexSpecs && indexSpecs.length > 0) {
76-
// Parse index specs and create composite store
91+
// Parse index specs
7792
const specs = parseIndexSpecs(indexSpecs);
78-
store = await CompositeStoreReader.fromSpecs(specs);
7993
indexNames = specs.map((s) => s.displayName);
94+
95+
if (agentManaged) {
96+
// Agent-managed + remote indexes: use LayeredStore
97+
const remoteStore = await CompositeStoreReader.fromSpecs(specs);
98+
store = new LayeredStore(new FilesystemStore(), remoteStore);
99+
} else {
100+
// Fixed mode: use read-only CompositeStoreReader
101+
store = await CompositeStoreReader.fromSpecs(specs);
102+
}
80103
} else {
81-
// No --index: use default store, serve all
104+
// No --index: use FilesystemStore (agent-managed mode)
82105
store = new FilesystemStore();
83106
// Dynamic indexing: server can start with zero indexes
84107
// Use list_indexes to see available indexes, index_repo to create new ones
@@ -98,11 +121,13 @@ const httpCommand = new Command("http")
98121
const apiKey = options.apiKey ?? process.env.MCP_API_KEY;
99122

100123
// Start HTTP server
124+
// agentManaged: true when no -i flags (dynamic mode), false when -i flags provided (fixed mode)
101125
const { runMCPHttpServer } = await import("../clients/mcp-http-server.js");
102126
const server = await runMCPHttpServer({
103127
store,
104128
indexNames,
105129
searchOnly: options.searchOnly,
130+
agentManaged: !indexSpecs || indexSpecs.length === 0,
106131
port: parseInt(options.port, 10),
107132
host: options.host,
108133
cors,

0 commit comments

Comments
 (0)