@semanticintent/semantic-chirp-intelligence-mcp 3.1.0 โ†’ 4.0.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.
@@ -1,222 +0,0 @@
1
- /**
2
- * Semantic Intent Parser - Proof of Concept
3
- *
4
- * Tests the fundamental premise: Can we reliably extract tool configuration
5
- * from natural language semantic intent?
6
- *
7
- * This is a minimal viable test to validate the concept before building
8
- * the full universal MCP architecture.
9
- */
10
- /**
11
- * Basic semantic intent parser using regex patterns
12
- */
13
- export class SemanticIntentParser {
14
- static CAPABILITY_MAPPINGS = {
15
- 'web search': 'web_search',
16
- 'search': 'web_search',
17
- 'API calls': 'yahoo_api',
18
- 'api': 'yahoo_api',
19
- 'data analysis': 'data_analysis',
20
- 'analyze': 'data_analysis',
21
- 'statistical analysis': 'data_analysis',
22
- 'advice': 'chirp_generation',
23
- 'recommendations': 'chirp_generation',
24
- };
25
- /**
26
- * Parse semantic intent and extract configuration
27
- */
28
- parseIntent(intent) {
29
- const needsMatch = intent.match(/I need:\s*([^]+?)(?=\nI\s+(?:will|return|estimate)|$)/i);
30
- const willMatch = intent.match(/I will:\s*([^]+?)(?=\nI\s+(?:need|return|estimate)|$)/i);
31
- const parameters = needsMatch ? this.extractParameters(needsMatch[1]) : [];
32
- const capabilities = willMatch ? this.mapCapabilities(willMatch[1]) : [];
33
- // Calculate confidence based on what we successfully parsed
34
- let confidence = 0.5;
35
- if (needsMatch)
36
- confidence += 0.25;
37
- if (willMatch)
38
- confidence += 0.25;
39
- return {
40
- parameters,
41
- capabilities,
42
- confidence
43
- };
44
- }
45
- /**
46
- * Extract parameter definitions from "I need:" section
47
- * Handles patterns like:
48
- * - "player name (required string)"
49
- * - "date range (optional)"
50
- * - "analysis depth (optional enum: basic|detailed)"
51
- */
52
- extractParameters(needsSection) {
53
- const parameters = [];
54
- const paramLines = needsSection.split(',').map(line => line.trim());
55
- for (const line of paramLines) {
56
- const param = this.parseParameterLine(line);
57
- if (param) {
58
- parameters.push(param);
59
- }
60
- }
61
- return parameters;
62
- }
63
- /**
64
- * Parse a single parameter line
65
- */
66
- parseParameterLine(line) {
67
- // Match patterns like "player name (required string)" or "date (optional)"
68
- const match = line.match(/([^(]+)\s*\(([^)]+)\)/);
69
- if (!match)
70
- return null;
71
- const nameRaw = match[1].trim();
72
- const specification = match[2].trim().toLowerCase();
73
- // Convert "player name" to "player_name"
74
- const name = nameRaw.replace(/\s+/g, '_').toLowerCase();
75
- // Determine if required
76
- const required = specification.includes('required');
77
- // Infer type from specification
78
- const type = this.inferParameterType(specification);
79
- return {
80
- name,
81
- type,
82
- required,
83
- description: line.trim()
84
- };
85
- }
86
- /**
87
- * Infer parameter type from specification string
88
- */
89
- inferParameterType(specification) {
90
- if (specification.includes('string'))
91
- return 'string';
92
- if (specification.includes('number'))
93
- return 'number';
94
- if (specification.includes('boolean'))
95
- return 'boolean';
96
- if (specification.includes('array'))
97
- return 'array';
98
- if (specification.includes('object'))
99
- return 'object';
100
- return 'string'; // Default to string
101
- }
102
- /**
103
- * Map capability descriptions to capability identifiers
104
- */
105
- mapCapabilities(willSection) {
106
- const capabilities = new Set();
107
- const text = willSection.toLowerCase();
108
- for (const [phrase, capability] of Object.entries(SemanticIntentParser.CAPABILITY_MAPPINGS)) {
109
- if (text.includes(phrase.toLowerCase())) {
110
- capabilities.add(capability);
111
- }
112
- }
113
- return Array.from(capabilities);
114
- }
115
- }
116
- /**
117
- * Test tool definitions for validation
118
- */
119
- export const TEST_SEMANTIC_TOOLS = {
120
- quickPlayerStats: {
121
- name: "test_quick_player_stats",
122
- semanticIntent: `
123
- Given a player name, I will get their basic stats from Yahoo API.
124
-
125
- I need: player name (required string)
126
- I will: API calls
127
- I return: goals, assists, points
128
- I estimate: simple, 500 tokens
129
- `
130
- },
131
- injuryCheck: {
132
- name: "test_injury_check",
133
- semanticIntent: `
134
- Given a player name, I will search for injury news and check Yahoo status.
135
-
136
- I need: player name (required string), include historical (optional boolean)
137
- I will: web search, API calls
138
- I return: injury status and timeline
139
- I estimate: moderate, 2000 tokens
140
- `
141
- },
142
- tradeAnalysis: {
143
- name: "test_trade_analysis",
144
- semanticIntent: `
145
- Given player names, I will analyze stats and provide trade recommendation.
146
-
147
- I need: your players (required array), their players (required array)
148
- I will: API calls, data analysis, recommendations
149
- I return: trade verdict with confidence score
150
- I estimate: complex, 5000 tokens
151
- `
152
- }
153
- };
154
- /**
155
- * Validation function to test parser accuracy
156
- */
157
- export function validateParser() {
158
- const parser = new SemanticIntentParser();
159
- const results = [];
160
- // Test 1: Quick Player Stats
161
- const test1 = parser.parseIntent(TEST_SEMANTIC_TOOLS.quickPlayerStats.semanticIntent);
162
- const expected1 = {
163
- parameters: [{ name: 'player_name', type: 'string', required: true }],
164
- capabilities: ['yahoo_api']
165
- };
166
- const match1 = test1.parameters.length === 1 &&
167
- test1.parameters[0].name === 'player_name' &&
168
- test1.parameters[0].required === true &&
169
- test1.capabilities.includes('yahoo_api');
170
- results.push({
171
- tool: 'quickPlayerStats',
172
- parsed: test1,
173
- expected: expected1,
174
- match: match1
175
- });
176
- // Test 2: Injury Check
177
- const test2 = parser.parseIntent(TEST_SEMANTIC_TOOLS.injuryCheck.semanticIntent);
178
- const expected2 = {
179
- parameters: [
180
- { name: 'player_name', type: 'string', required: true },
181
- { name: 'include_historical', type: 'boolean', required: false }
182
- ],
183
- capabilities: ['web_search', 'yahoo_api']
184
- };
185
- const match2 = test2.parameters.length === 2 &&
186
- test2.parameters[0].name === 'player_name' &&
187
- test2.parameters[1].name === 'include_historical' &&
188
- test2.parameters[1].type === 'boolean' &&
189
- test2.capabilities.includes('web_search') &&
190
- test2.capabilities.includes('yahoo_api');
191
- results.push({
192
- tool: 'injuryCheck',
193
- parsed: test2,
194
- expected: expected2,
195
- match: match2
196
- });
197
- // Test 3: Trade Analysis
198
- const test3 = parser.parseIntent(TEST_SEMANTIC_TOOLS.tradeAnalysis.semanticIntent);
199
- const expected3 = {
200
- parameters: [
201
- { name: 'your_players', type: 'array', required: true },
202
- { name: 'their_players', type: 'array', required: true }
203
- ],
204
- capabilities: ['yahoo_api', 'data_analysis', 'chirp_generation']
205
- };
206
- const match3 = test3.parameters.length === 2 &&
207
- test3.parameters[0].name === 'your_players' &&
208
- test3.parameters[0].type === 'array' &&
209
- test3.capabilities.includes('yahoo_api') &&
210
- test3.capabilities.includes('data_analysis');
211
- results.push({
212
- tool: 'tradeAnalysis',
213
- parsed: test3,
214
- expected: expected3,
215
- match: match3
216
- });
217
- const allMatch = results.every(r => r.match);
218
- return {
219
- success: allMatch,
220
- results
221
- };
222
- }
@@ -1,146 +0,0 @@
1
- /**
2
- * Semantic Tool Integration - Live Test
3
- *
4
- * Adds a semantic intent-driven tool to the existing MCP server
5
- * for end-to-end validation without disrupting working tools.
6
- */
7
- import { SemanticIntentParser } from './semantic-intent-parser.js';
8
- /**
9
- * Semantic test tool definition
10
- */
11
- export const SEMANTIC_PLAYER_COMPARISON = {
12
- name: "semantic_player_comparison",
13
- description: "EXPERIMENTAL: Compare two players using semantic intent parsing",
14
- semanticIntent: `
15
- Given two player names, I will get their current season stats from Yahoo API
16
- and return a simple comparison of goals, assists, points, and plus/minus.
17
-
18
- I need: player1 (required string), player2 (required string)
19
- I will: API calls, data analysis
20
- I return: side-by-side player comparison
21
- I estimate: simple analysis, 1000 tokens
22
- `
23
- };
24
- /**
25
- * Parse semantic intent and return configuration
26
- */
27
- export function parsePlayerComparisonIntent() {
28
- const parser = new SemanticIntentParser();
29
- return parser.parseIntent(SEMANTIC_PLAYER_COMPARISON.semanticIntent);
30
- }
31
- /**
32
- * Helper to get parsed input schema for MCP tool registration
33
- */
34
- export function getPlayerComparisonInputSchema() {
35
- const parsed = parsePlayerComparisonIntent();
36
- // Convert parsed parameters to MCP input schema
37
- const properties = {};
38
- const required = [];
39
- for (const param of parsed.parameters) {
40
- properties[param.name] = {
41
- type: param.type,
42
- description: param.description
43
- };
44
- if (param.required) {
45
- required.push(param.name);
46
- }
47
- }
48
- return {
49
- type: "object",
50
- properties,
51
- required
52
- };
53
- }
54
- /**
55
- * Execute the semantic tool with player comparison logic
56
- */
57
- export async function executePlayerComparison(args, getPlayerStatsFunc, searchPlayersFunc) {
58
- const parsed = parsePlayerComparisonIntent();
59
- // Validate required parameters based on parsed intent
60
- if (!args.player1 || !args.player2) {
61
- throw new Error(`Missing required parameters: ${parsed.parameters.filter(p => p.required).map(p => p.name).join(', ')}`);
62
- }
63
- try {
64
- // Step 1: Search for players across multiple position groups for better coverage
65
- // Yahoo API limits results per query, so we search across positions and combine
66
- const positions = ['C', 'LW', 'RW', 'D', 'G', undefined]; // undefined = all positions
67
- const searchPromises = positions.map(pos => searchPlayersFunc(pos, 100));
68
- const allSearchResults = await Promise.all(searchPromises);
69
- // Combine all players from different searches
70
- const allPlayers = [];
71
- for (const result of allSearchResults) {
72
- if (result.players) {
73
- allPlayers.push(...result.players);
74
- }
75
- }
76
- // Remove duplicates based on player_id
77
- const uniquePlayers = Array.from(new Map(allPlayers.map((p) => [p.player_id, p])).values());
78
- // Find matching players by name (case-insensitive, flexible matching)
79
- const findPlayer = (playerName) => {
80
- const searchName = playerName.toLowerCase().trim();
81
- return uniquePlayers.find((p) => {
82
- const playerFullName = (p.name || '').toLowerCase();
83
- // Match if either name contains the other, or exact match
84
- return playerFullName.includes(searchName) ||
85
- searchName.includes(playerFullName) ||
86
- playerFullName === searchName;
87
- });
88
- };
89
- const player1Match = findPlayer(args.player1);
90
- const player2Match = findPlayer(args.player2);
91
- if (!player1Match) {
92
- throw new Error(`Could not find player: ${args.player1}. Searched ${uniquePlayers.length} unique players across ${allSearchResults.length} position groups.`);
93
- }
94
- if (!player2Match) {
95
- throw new Error(`Could not find player: ${args.player2}. Searched ${uniquePlayers.length} unique players across ${allSearchResults.length} position groups.`);
96
- }
97
- // Step 2: Get detailed stats for both players
98
- const [player1Stats, player2Stats] = await Promise.all([
99
- getPlayerStatsFunc(player1Match.player_id),
100
- getPlayerStatsFunc(player2Match.player_id)
101
- ]);
102
- // Step 3: Format comparison
103
- const comparison = {
104
- player1: {
105
- name: player1Stats.name,
106
- team: player1Stats.team,
107
- position: player1Stats.position,
108
- stats: {
109
- goals: player1Stats.stats.goals || 0,
110
- assists: player1Stats.stats.assists || 0,
111
- points: player1Stats.stats.points || 0,
112
- plus_minus: player1Stats.stats.plus_minus || 0
113
- }
114
- },
115
- player2: {
116
- name: player2Stats.name,
117
- team: player2Stats.team,
118
- position: player2Stats.position,
119
- stats: {
120
- goals: player2Stats.stats.goals || 0,
121
- assists: player2Stats.stats.assists || 0,
122
- points: player2Stats.stats.points || 0,
123
- plus_minus: player2Stats.stats.plus_minus || 0
124
- }
125
- },
126
- winner: {
127
- goals: player1Stats.stats.goals > player2Stats.stats.goals ? player1Stats.name : player2Stats.name,
128
- assists: player1Stats.stats.assists > player2Stats.stats.assists ? player1Stats.name : player2Stats.name,
129
- points: player1Stats.stats.points > player2Stats.stats.points ? player1Stats.name : player2Stats.name,
130
- plus_minus: player1Stats.stats.plus_minus > player2Stats.stats.plus_minus ? player1Stats.name : player2Stats.name
131
- },
132
- _debug: {
133
- semanticIntentParsing: {
134
- parsedParameters: parsed.parameters,
135
- parsedCapabilities: parsed.capabilities,
136
- parseConfidence: `${(parsed.confidence * 100).toFixed(0)}%`,
137
- message: "โœ… Tool configuration auto-generated from semantic intent!"
138
- }
139
- }
140
- };
141
- return comparison;
142
- }
143
- catch (error) {
144
- throw new Error(`Player comparison failed: ${error instanceof Error ? error.message : String(error)}`);
145
- }
146
- }
@@ -1,61 +0,0 @@
1
- /**
2
- * Test script for semantic intent parser
3
- * Run this to validate the POC works
4
- */
5
- import { SemanticIntentParser, validateParser, TEST_SEMANTIC_TOOLS } from './semantic-intent-parser.js';
6
- console.log('='.repeat(80));
7
- console.log('SEMANTIC INTENT PARSER - PROOF OF CONCEPT TEST');
8
- console.log('='.repeat(80));
9
- console.log();
10
- // Test individual tool parsing
11
- console.log('๐Ÿ“ Testing individual tool parsing:\n');
12
- const parser = new SemanticIntentParser();
13
- for (const [key, tool] of Object.entries(TEST_SEMANTIC_TOOLS)) {
14
- console.log(`\n๐Ÿ”ง Tool: ${tool.name}`);
15
- console.log('โ”€'.repeat(80));
16
- console.log('Intent:');
17
- console.log(tool.semanticIntent.trim());
18
- console.log();
19
- const parsed = parser.parseIntent(tool.semanticIntent);
20
- console.log('Parsed Configuration:');
21
- console.log(' Parameters:', JSON.stringify(parsed.parameters, null, 4));
22
- console.log(' Capabilities:', parsed.capabilities);
23
- console.log(' Confidence:', `${(parsed.confidence * 100).toFixed(0)}%`);
24
- }
25
- console.log('\n' + '='.repeat(80));
26
- console.log('๐Ÿงช VALIDATION TEST RESULTS');
27
- console.log('='.repeat(80));
28
- console.log();
29
- // Run comprehensive validation
30
- const validation = validateParser();
31
- for (const result of validation.results) {
32
- const icon = result.match ? 'โœ…' : 'โŒ';
33
- console.log(`${icon} ${result.tool}: ${result.match ? 'PASS' : 'FAIL'}`);
34
- if (!result.match) {
35
- console.log(' Expected:', JSON.stringify(result.expected, null, 2));
36
- console.log(' Got:', JSON.stringify(result.parsed, null, 2));
37
- }
38
- }
39
- console.log();
40
- console.log('โ”€'.repeat(80));
41
- console.log(`Overall Result: ${validation.success ? 'โœ… ALL TESTS PASSED' : 'โŒ SOME TESTS FAILED'}`);
42
- console.log('โ”€'.repeat(80));
43
- console.log('\n๐Ÿ“Š ANALYSIS:\n');
44
- if (validation.success) {
45
- console.log('โœ… The semantic intent parser successfully extracted:');
46
- console.log(' โ€ข Parameter names, types, and required/optional flags');
47
- console.log(' โ€ข Capability requirements from action descriptions');
48
- console.log(' โ€ข Confidence scores based on parse completeness');
49
- console.log();
50
- console.log('๐ŸŽฏ RECOMMENDATION: The foundation is solid!');
51
- console.log(' The basic premise works - semantic intent can reliably generate tool configuration.');
52
- console.log(' You can proceed with confidence to build the full universal architecture.');
53
- }
54
- else {
55
- console.log('โš ๏ธ The parser had issues extracting configuration correctly.');
56
- console.log(' Review the failed tests above to understand parsing limitations.');
57
- console.log(' The regex patterns may need refinement, or the concept needs rethinking.');
58
- }
59
- console.log('\n' + '='.repeat(80));
60
- // Exit with appropriate code
61
- process.exit(validation.success ? 0 : 1);