Skip to content

Commit e51523c

Browse files
napoleondclaude
andcommitted
feat(search): add date filtering with --start-date and --end-date flags
Support startPublishedDate and endPublishedDate parameters on the search_search MCP tool, allowing users to restrict results by publication date. Also fixes toolArgs extraction to properly skip flag values that would otherwise leak into the query string. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent ab6c925 commit e51523c

2 files changed

Lines changed: 43 additions & 7 deletions

File tree

packages/atxp/src/commands/search.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,26 @@ import chalk from 'chalk';
44
const SERVER = 'search.mcp.atxp.ai';
55
const TOOL = 'search_search';
66

7-
export async function searchCommand(query: string): Promise<void> {
7+
export interface SearchOptions {
8+
startDate?: string;
9+
endDate?: string;
10+
}
11+
12+
export async function searchCommand(query: string, options: SearchOptions = {}): Promise<void> {
813
if (!query || query.trim().length === 0) {
914
console.error(chalk.red('Error: Search query is required'));
1015
console.log(`Usage: ${chalk.cyan('npx atxp search <query>')}`);
1116
process.exit(1);
1217
}
1318

14-
const result = await callTool(SERVER, TOOL, { query: query.trim() });
19+
const args: Record<string, unknown> = { query: query.trim() };
20+
if (options.startDate) {
21+
args.startPublishedDate = options.startDate;
22+
}
23+
if (options.endDate) {
24+
args.endPublishedDate = options.endDate;
25+
}
26+
27+
const result = await callTool(SERVER, TOOL, args);
1528
console.log(result);
1629
}

packages/atxp/src/index.ts

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { runDemo } from './run-demo.js';
77
import { showHelp } from './help.js';
88
import { checkAllDependencies, showDependencyError } from './check-dependencies.js';
99
import { login } from './login.js';
10-
import { searchCommand } from './commands/search.js';
10+
import { searchCommand, type SearchOptions } from './commands/search.js';
1111
import { imageCommand } from './commands/image.js';
1212
import { musicCommand } from './commands/music.js';
1313
import { videoCommand } from './commands/video.js';
@@ -114,6 +114,7 @@ function parseArgs(): {
114114
paasOptions: PaasOptions;
115115
paasArgs: string[];
116116
toolArgs: string;
117+
searchOptions: SearchOptions;
117118
memoryOptions: MemoryOptions;
118119
contactsOptions: ContactsOptionsLocal;
119120
} {
@@ -133,6 +134,7 @@ function parseArgs(): {
133134
paasOptions: {},
134135
paasArgs: [],
135136
toolArgs: '',
137+
searchOptions: {},
136138
memoryOptions: {},
137139
contactsOptions: {},
138140
};
@@ -189,8 +191,22 @@ function parseArgs(): {
189191
appName = args.find((arg) => !arg.startsWith('-') && arg !== 'create');
190192
}
191193

192-
// Get tool arguments (everything after the command)
193-
const toolArgs = process.argv.slice(3).filter((arg) => !arg.startsWith('-')).join(' ');
194+
// Get tool arguments (everything after the command), excluding flags and their values
195+
const toolArgs = (() => {
196+
const args = process.argv.slice(3);
197+
const result: string[] = [];
198+
for (let i = 0; i < args.length; i++) {
199+
if (args[i].startsWith('-')) {
200+
// Skip the flag and its value (if the next arg doesn't start with -)
201+
if (i + 1 < args.length && !args[i + 1].startsWith('-')) {
202+
i++;
203+
}
204+
} else {
205+
result.push(args[i]);
206+
}
207+
}
208+
return result.join(' ');
209+
})();
194210

195211
// Get all values for a repeatable flag (like --db can appear multiple times)
196212
const getAllArgValues = (flag: string): string[] => {
@@ -270,6 +286,12 @@ function parseArgs(): {
270286
direction: getArgValue('--direction', ''),
271287
};
272288

289+
// Parse search options
290+
const searchOptions: SearchOptions = {
291+
startDate: getArgValue('--start-date', ''),
292+
endDate: getArgValue('--end-date', ''),
293+
};
294+
273295
// Parse memory options
274296
const memoryOptions: MemoryOptions = {
275297
path: getArgValue('--path', ''),
@@ -295,12 +317,13 @@ function parseArgs(): {
295317
paasOptions,
296318
paasArgs,
297319
toolArgs,
320+
searchOptions,
298321
memoryOptions,
299322
contactsOptions,
300323
};
301324
}
302325

303-
const { command, subCommand, demoOptions, createOptions, loginOptions, emailOptions, phoneOptions, paasOptions, paasArgs, toolArgs, memoryOptions, contactsOptions } = parseArgs();
326+
const { command, subCommand, demoOptions, createOptions, loginOptions, emailOptions, phoneOptions, paasOptions, paasArgs, toolArgs, searchOptions, memoryOptions, contactsOptions } = parseArgs();
304327

305328
// Extract positional args from argv, skipping flag values (e.g., --path <val> --topk <val>)
306329
function extractPositionalArgs(startIndex: number): string {
@@ -367,7 +390,7 @@ async function main() {
367390
break;
368391

369392
case 'search':
370-
await searchCommand(toolArgs);
393+
await searchCommand(toolArgs, searchOptions);
371394
break;
372395

373396
case 'image':

0 commit comments

Comments
 (0)