@hyperweb/telescope 1.15.2 → 1.17.1
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 +5 -5
- package/main/generators/create-combined-stargate-clients.js +99 -0
- package/main/generators/create-helpers.js +15 -8
- package/main/generators/create-mcp-server.js +153 -279
- package/main/generators/create-root-readme.js +1 -1
- package/main/helpers/external-icjs.js +29 -19
- package/main/helpers/generated-type.js +24 -0
- package/main/helpers/helper-func-types-interface.js +8 -8
- package/main/helpers/helper-func-types.js +8 -8
- package/main/helpers/internalForBigInt.js +248 -0
- package/main/helpers/types.js +24 -0
- package/main/helpers/vue-query.js +91 -0
- package/main/protod/proto-download.js +57 -0
- package/module/generators/create-combined-stargate-clients.js +95 -0
- package/module/generators/create-helpers.js +15 -8
- package/module/generators/create-mcp-server.js +153 -279
- package/module/generators/create-root-readme.js +1 -1
- package/module/helpers/external-icjs.js +29 -19
- package/module/helpers/generated-type.js +21 -0
- package/module/helpers/helper-func-types-interface.js +8 -8
- package/module/helpers/helper-func-types.js +8 -8
- package/module/helpers/internalForBigInt.js +245 -0
- package/module/helpers/types.js +21 -0
- package/module/helpers/vue-query.js +87 -0
- package/module/protod/proto-download.js +55 -0
- package/module/telescope.js +0 -0
- package/package.json +6 -6
- package/src/generators/create-helpers.ts +29 -16
- package/src/generators/create-mcp-server.ts +154 -282
- package/src/generators/create-root-readme.ts +1 -1
- package/src/helpers/external-icjs.ts +29 -19
- package/src/helpers/helper-func-types-interface.ts +8 -8
- package/src/helpers/helper-func-types.ts +8 -8
- package/types/codegen/cosmos/orm/module/v1alpha1/module.d.ts +43 -0
- package/types/helpers/external-icjs.d.ts +1 -1
|
@@ -14,7 +14,7 @@ export const plugin = (builder, bundler) => {
|
|
|
14
14
|
mkdirSync(mcpServerPath, { recursive: true });
|
|
15
15
|
mkdirSync(join(mcpServerPath, 'src'), { recursive: true });
|
|
16
16
|
mkdirSync(join(mcpServerPath, 'src', 'prompts'), { recursive: true });
|
|
17
|
-
mkdirSync(join(mcpServerPath, 'src',
|
|
17
|
+
mkdirSync(join(mcpServerPath, 'src', `${packageName}-examples`), { recursive: true });
|
|
18
18
|
// Generate package.json for MCP server
|
|
19
19
|
const packageJson = generateMcpPackageJson(packageName);
|
|
20
20
|
writeFileSync(join(mcpServerPath, 'package.json'), JSON.stringify(packageJson, null, 2));
|
|
@@ -80,8 +80,8 @@ async function main() {
|
|
|
80
80
|
|
|
81
81
|
// Register blockchain function generator tool
|
|
82
82
|
server.tool(
|
|
83
|
-
'
|
|
84
|
-
'
|
|
83
|
+
'use-${packageName}',
|
|
84
|
+
'Analyzes requests and provides step-by-step implementation guidance for custom blockchain functions using telescope examples as reference',
|
|
85
85
|
{
|
|
86
86
|
task: z.string().describe('The blockchain task to implement (e.g., "get balance", "check staking rewards", "query validators")').optional(),
|
|
87
87
|
chainName: z.string().describe('The blockchain name (e.g., cosmos, osmosis, injective)').optional(),
|
|
@@ -93,7 +93,7 @@ async function main() {
|
|
|
93
93
|
const { task = 'get account balance', chainName = 'cosmos', functionType = 'query', customRequirements } = args;
|
|
94
94
|
|
|
95
95
|
// Read available examples
|
|
96
|
-
const examplesPath = resolve(__dirname, '
|
|
96
|
+
const examplesPath = resolve(__dirname, '${packageName}-examples');
|
|
97
97
|
let availableExamples: string[] = [];
|
|
98
98
|
|
|
99
99
|
try {
|
|
@@ -132,7 +132,7 @@ async function main() {
|
|
|
132
132
|
'## Instructions for Implementation',
|
|
133
133
|
'',
|
|
134
134
|
'### Step 1: Review Available Examples',
|
|
135
|
-
|
|
135
|
+
\`The following example files are available in \\\`src/${packageName}-examples/\\\`:\`,
|
|
136
136
|
'',
|
|
137
137
|
examplesList,
|
|
138
138
|
'',
|
|
@@ -220,8 +220,8 @@ async function main() {
|
|
|
220
220
|
'',
|
|
221
221
|
'## Additional Resources',
|
|
222
222
|
'',
|
|
223
|
-
|
|
224
|
-
|
|
223
|
+
\`- **Full codebase reference**: \\\`src/${packageName}/\\\` directory contains all generated types and functions\`,
|
|
224
|
+
\`- **Configuration examples**: \\\`src/${packageName}-examples/config-example.ts\\\`\`,
|
|
225
225
|
'- **Chain registry data**: \`src/prompts/chains.json\`',
|
|
226
226
|
'- **Usage guidelines**: Use the \`codegen-usage\` and \`agent-guidelines\` prompts for detailed instructions',
|
|
227
227
|
'',
|
|
@@ -232,7 +232,7 @@ async function main() {
|
|
|
232
232
|
'3. Test your implementation with proper error handling',
|
|
233
233
|
'4. Ensure proper TypeScript types are used',
|
|
234
234
|
'',
|
|
235
|
-
|
|
235
|
+
\`The examples in \\\`${packageName}-examples/\\\` are production-ready patterns that you can adapt for any blockchain task.\`
|
|
236
236
|
].filter(line => line !== '').join('\\n');
|
|
237
237
|
|
|
238
238
|
return {
|
|
@@ -340,11 +340,8 @@ main().catch((error) => {
|
|
|
340
340
|
});
|
|
341
341
|
`;
|
|
342
342
|
writeFileSync(join(mcpServerPath, 'src', 'index.ts'), indexContent);
|
|
343
|
-
// Generate telescope loader utility
|
|
344
|
-
const telescopeLoaderCode = generateTelescopeLoader(packageName);
|
|
345
|
-
writeFileSync(join(mcpServerPath, 'src', 'telescope-loader.ts'), telescopeLoaderCode);
|
|
346
343
|
// Generate TypeScript configuration
|
|
347
|
-
const tsConfig = generateTsConfig();
|
|
344
|
+
const tsConfig = generateTsConfig(packageName);
|
|
348
345
|
writeFileSync(join(mcpServerPath, 'tsconfig.json'), JSON.stringify(tsConfig, null, 2));
|
|
349
346
|
// Generate README
|
|
350
347
|
const readme = generateReadme(packageName);
|
|
@@ -358,13 +355,13 @@ main().catch((error) => {
|
|
|
358
355
|
};
|
|
359
356
|
function generateMcpPackageJson(packageName) {
|
|
360
357
|
return {
|
|
361
|
-
name:
|
|
358
|
+
name: `${packageName}-mcp`,
|
|
362
359
|
version: "0.1.0",
|
|
363
360
|
description: `MCP server for ${packageName} blockchain interactions`,
|
|
364
361
|
main: "dist/index.js",
|
|
365
362
|
type: "module",
|
|
366
363
|
bin: {
|
|
367
|
-
[
|
|
364
|
+
[`${packageName}-mcp-server`]: "./dist/index.js"
|
|
368
365
|
},
|
|
369
366
|
scripts: {
|
|
370
367
|
build: "rimraf dist && tsc",
|
|
@@ -391,104 +388,7 @@ function generateMcpPackageJson(packageName) {
|
|
|
391
388
|
}
|
|
392
389
|
};
|
|
393
390
|
}
|
|
394
|
-
function
|
|
395
|
-
const outputDirName = basename(builder.outPath);
|
|
396
|
-
const packageName = outputDirName || bundler.bundle.base;
|
|
397
|
-
return `#!/usr/bin/env node
|
|
398
|
-
|
|
399
|
-
import { readFileSync } from 'node:fs';
|
|
400
|
-
import { dirname, resolve } from 'node:path';
|
|
401
|
-
import { fileURLToPath } from 'node:url';
|
|
402
|
-
|
|
403
|
-
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
404
|
-
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
405
|
-
import { z } from 'zod';
|
|
406
|
-
|
|
407
|
-
// NOTE: Tool imports are commented out since they are excluded from build
|
|
408
|
-
// Uncomment and modify these imports if you want to include tools in your build
|
|
409
|
-
/*
|
|
410
|
-
import { getBalanceTool } from './tools/getBalance.js';
|
|
411
|
-
import { getBalanceReactTool } from './tools/useBalance.js';
|
|
412
|
-
*/
|
|
413
|
-
|
|
414
|
-
// Get package.json version
|
|
415
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
416
|
-
const __dirname = dirname(__filename);
|
|
417
|
-
const packageJson = JSON.parse(readFileSync(resolve(__dirname, '../package.json'), 'utf8'));
|
|
418
|
-
const VERSION = packageJson.version;
|
|
419
|
-
|
|
420
|
-
async function main() {
|
|
421
|
-
const server = new McpServer({
|
|
422
|
-
name: '${packageName} MCP Server',
|
|
423
|
-
version: VERSION,
|
|
424
|
-
});
|
|
425
|
-
|
|
426
|
-
// Add prompts for AI agents
|
|
427
|
-
server.prompt(
|
|
428
|
-
'codegen-usage',
|
|
429
|
-
'Guide for using telescope generated code',
|
|
430
|
-
async () => {
|
|
431
|
-
const promptPath = resolve(__dirname, 'prompts/codegen-usage.md');
|
|
432
|
-
const content = readFileSync(promptPath, 'utf-8');
|
|
433
|
-
return {
|
|
434
|
-
messages: [{
|
|
435
|
-
role: 'user',
|
|
436
|
-
content: {
|
|
437
|
-
type: 'text',
|
|
438
|
-
text: content
|
|
439
|
-
}
|
|
440
|
-
}]
|
|
441
|
-
};
|
|
442
|
-
}
|
|
443
|
-
);
|
|
444
|
-
|
|
445
|
-
server.prompt(
|
|
446
|
-
'agent-guidelines',
|
|
447
|
-
'Guidelines for MCP agents using ${packageName}',
|
|
448
|
-
async () => {
|
|
449
|
-
const promptPath = resolve(__dirname, 'prompts/agent-guidelines.md');
|
|
450
|
-
const content = readFileSync(promptPath, 'utf-8');
|
|
451
|
-
return {
|
|
452
|
-
messages: [{
|
|
453
|
-
role: 'user',
|
|
454
|
-
content: {
|
|
455
|
-
type: 'text',
|
|
456
|
-
text: content
|
|
457
|
-
}
|
|
458
|
-
}]
|
|
459
|
-
};
|
|
460
|
-
}
|
|
461
|
-
);
|
|
462
|
-
|
|
463
|
-
// NOTE: Tool registrations are commented out since tool functions are not imported
|
|
464
|
-
// Uncomment and modify these registrations if you want to include tools in your build
|
|
465
|
-
/*
|
|
466
|
-
// Register tools
|
|
467
|
-
server.tool('get-balance', 'Get account balance for a specific token', {
|
|
468
|
-
address: z.string().describe('The account address'),
|
|
469
|
-
chainName: z.string().describe('The blockchain name (e.g., cosmos, osmosis)').optional(),
|
|
470
|
-
denom: z.string().describe('The token denomination (e.g., uatom, uosmo)').optional()
|
|
471
|
-
}, getBalanceTool);
|
|
472
|
-
|
|
473
|
-
server.tool('get-balance-react', 'Get balance using React hook pattern', {
|
|
474
|
-
address: z.string().describe('The account address'),
|
|
475
|
-
chainName: z.string().describe('The blockchain name').optional(),
|
|
476
|
-
displayDenom: z.string().describe('The display denomination').optional()
|
|
477
|
-
}, getBalanceReactTool);
|
|
478
|
-
*/
|
|
479
|
-
|
|
480
|
-
const transport = new StdioServerTransport();
|
|
481
|
-
await server.connect(transport);
|
|
482
|
-
console.log('${packageName} MCP server started on stdio');
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
main().catch((error) => {
|
|
486
|
-
console.error('Fatal error in main()', error);
|
|
487
|
-
process.exit(1);
|
|
488
|
-
});
|
|
489
|
-
`;
|
|
490
|
-
}
|
|
491
|
-
function generateTsConfig() {
|
|
391
|
+
function generateTsConfig(packageName) {
|
|
492
392
|
return {
|
|
493
393
|
compilerOptions: {
|
|
494
394
|
target: "ES2022",
|
|
@@ -507,15 +407,13 @@ function generateTsConfig() {
|
|
|
507
407
|
resolveJsonModule: true
|
|
508
408
|
},
|
|
509
409
|
include: ["src/**/*"],
|
|
510
|
-
exclude: ["node_modules", "dist",
|
|
410
|
+
exclude: ["node_modules", "dist", `src/${packageName}/**/*`, `src/${packageName}-examples/**/*`]
|
|
511
411
|
};
|
|
512
412
|
}
|
|
513
413
|
function generateReadme(packageName) {
|
|
514
414
|
return `# ${packageName.charAt(0).toUpperCase() + packageName.slice(1)} MCP Server
|
|
515
415
|
|
|
516
|
-
This MCP server provides AI agents with
|
|
517
|
-
|
|
518
|
-
**Note**: This MCP server contains a complete copy of the telescope generated codebase in \`src/telescope/\` for AI agents to reference, but uses mock implementations for demonstration. The telescope code is excluded from the build process.
|
|
416
|
+
This MCP server provides AI agents with the \`use-${packageName}\` tool to create custom blockchain functions using telescope examples as reference.
|
|
519
417
|
|
|
520
418
|
## Installation
|
|
521
419
|
|
|
@@ -544,12 +442,19 @@ Add this configuration to your AI agent's MCP settings:
|
|
|
544
442
|
|
|
545
443
|
This MCP server provides:
|
|
546
444
|
|
|
547
|
-
- **
|
|
548
|
-
- **
|
|
549
|
-
- **
|
|
550
|
-
- **
|
|
445
|
+
- **Function Generator Tool**: Single tool (\`use-${packageName}\`) that analyzes requests and provides step-by-step implementation guidance
|
|
446
|
+
- **Telescope Codebase Reference**: Complete telescope-generated code in \`src/${packageName}/\` as primary reference
|
|
447
|
+
- **Production Examples**: Reference implementations in \`src/${packageName}-examples/\` showing real-world patterns
|
|
448
|
+
- **AI Guidance**: Contextual prompts to help agents understand blockchain development patterns
|
|
449
|
+
|
|
450
|
+
## How It Works
|
|
551
451
|
|
|
552
|
-
|
|
452
|
+
The function generator tool:
|
|
453
|
+
|
|
454
|
+
1. **Analyzes your request** (task, chain, function type, custom requirements)
|
|
455
|
+
2. **Finds relevant examples** from \`${packageName}-examples/\` directory
|
|
456
|
+
3. **Provides implementation patterns** using \`${packageName}/\` codebase as primary reference
|
|
457
|
+
4. **Shows proper imports** and configuration with error handling
|
|
553
458
|
|
|
554
459
|
## Development
|
|
555
460
|
|
|
@@ -559,12 +464,16 @@ npm run inspector # Run MCP inspector for testing
|
|
|
559
464
|
npm run clean # Clean dist directory
|
|
560
465
|
\`\`\`
|
|
561
466
|
|
|
562
|
-
|
|
467
|
+
## Extending Examples
|
|
468
|
+
|
|
469
|
+
You can enhance the AI agent's knowledge by adding more examples to the \`${packageName}-examples/\` directory. The function generator automatically scans this directory, so new examples are immediately available for reference.
|
|
470
|
+
|
|
471
|
+
## Directory Structure
|
|
563
472
|
|
|
564
473
|
\`\`\`
|
|
565
474
|
${packageName}-mcp/
|
|
566
475
|
├── src/
|
|
567
|
-
│ ├──
|
|
476
|
+
│ ├── ${packageName}/ # 📚 Telescope generated code (primary reference, excluded from build)
|
|
568
477
|
│ │ ├── cosmos/ # Full cosmos SDK modules
|
|
569
478
|
│ │ │ ├── bank/ # Balance queries, transfers
|
|
570
479
|
│ │ │ ├── staking/ # Validator operations
|
|
@@ -572,7 +481,7 @@ ${packageName}-mcp/
|
|
|
572
481
|
│ │ ├── osmosis/ # Osmosis DEX functionality
|
|
573
482
|
│ │ ├── ibc/ # Inter-blockchain communication
|
|
574
483
|
│ │ └── index.ts # Main exports
|
|
575
|
-
│ ├──
|
|
484
|
+
│ ├── ${packageName}-examples/ # 📖 Production examples (excluded from build)
|
|
576
485
|
│ │ ├── config-example.ts # Chain configuration setup
|
|
577
486
|
│ │ ├── useBalance.ts # Balance query React hooks
|
|
578
487
|
│ │ ├── useBalanceFunc.ts # Direct balance functions
|
|
@@ -586,23 +495,26 @@ ${packageName}-mcp/
|
|
|
586
495
|
│ │ ├── useGrants.ts # Authorization grants
|
|
587
496
|
│ │ └── useSendData.ts # Transaction preparation
|
|
588
497
|
│ ├── prompts/ # 🤖 Agent instruction files
|
|
589
|
-
│ │ ├── codegen-usage.md #
|
|
498
|
+
│ │ ├── codegen-usage.md # Implementation guide for agents
|
|
590
499
|
│ │ ├── agent-guidelines.md # Best practices for agents
|
|
591
500
|
│ │ └── chains.json # Chain registry data
|
|
592
|
-
│
|
|
593
|
-
|
|
594
|
-
├── dist/ # Compiled JavaScript (excludes telescope/ and telescope-examples/)
|
|
501
|
+
│ └── index.ts # MCP server with function generator tool
|
|
502
|
+
├── dist/ # Compiled JavaScript (excludes ${packageName}/ and ${packageName}-examples/)
|
|
595
503
|
└── package.json
|
|
596
504
|
\`\`\`
|
|
597
505
|
|
|
598
|
-
|
|
506
|
+
**Key Points:**
|
|
507
|
+
- \`src/${packageName}/\` contains the complete telescope-generated codebase as the **primary reference**
|
|
508
|
+
- \`src/${packageName}-examples/\` contains **production examples** for patterns and logic reference
|
|
509
|
+
- Both directories are excluded from TypeScript build but available for AI agents to read
|
|
510
|
+
- Examples may contain compilation errors - focus on logic and patterns, not direct copying
|
|
599
511
|
|
|
600
512
|
Generated by [Telescope](https://github.com/hyperweb-io/telescope) 🔭
|
|
601
513
|
`;
|
|
602
514
|
}
|
|
603
515
|
function copyTelescopeCodebase(builder, mcpServerPath, packageName) {
|
|
604
516
|
const sourcePath = builder.outPath;
|
|
605
|
-
const destPath = join(mcpServerPath, 'src',
|
|
517
|
+
const destPath = join(mcpServerPath, 'src', packageName);
|
|
606
518
|
// Copy the entire telescope generated directory
|
|
607
519
|
if (existsSync(sourcePath)) {
|
|
608
520
|
// Skip copy if destination already exists (avoids Windows file permission issues)
|
|
@@ -628,180 +540,143 @@ function copyTelescopeCodebase(builder, mcpServerPath, packageName) {
|
|
|
628
540
|
}
|
|
629
541
|
}
|
|
630
542
|
// Removed retry logic - no longer needed since we skip copy if destination exists
|
|
631
|
-
function
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
import { fileURLToPath } from 'node:url';
|
|
543
|
+
function generateComprehensivePrompts(mcpServerPath, packageName) {
|
|
544
|
+
// Generate codegen-usage.md with our updated content
|
|
545
|
+
const codegenUsageContent = `# Codegen Usage Guide
|
|
635
546
|
|
|
636
|
-
|
|
637
|
-
|
|
547
|
+
## Overview
|
|
548
|
+
This guide provides instructions for MCP agents on how to use the telescope generated code when implementing the \`use-${packageName}\` tool.
|
|
638
549
|
|
|
639
|
-
|
|
640
|
-
* Load telescope generated modules dynamically
|
|
641
|
-
* This utility helps MCP tools access the telescope codebase
|
|
642
|
-
*/
|
|
643
|
-
export class TelescopeLoader {
|
|
644
|
-
private basePath: string;
|
|
550
|
+
## Understanding the Structure
|
|
645
551
|
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
}
|
|
552
|
+
### Primary Reference: \`src/${packageName}/\` Directory
|
|
553
|
+
This is your **main reference** for understanding the complete telescope-generated codebase. It contains:
|
|
649
554
|
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
// This would typically read the directory structure
|
|
655
|
-
// For now, return common cosmos modules
|
|
656
|
-
return [
|
|
657
|
-
'cosmos/bank/v1beta1',
|
|
658
|
-
'cosmos/staking/v1beta1',
|
|
659
|
-
'cosmos/gov/v1beta1',
|
|
660
|
-
'cosmos/distribution/v1beta1',
|
|
661
|
-
'cosmwasm/wasm/v1',
|
|
662
|
-
'ibc/core/client/v1',
|
|
663
|
-
'osmosis/gamm/v1beta1'
|
|
664
|
-
];
|
|
665
|
-
}
|
|
555
|
+
- **Complete type definitions** for all blockchain modules
|
|
556
|
+
- **Client implementations** for queries and transactions
|
|
557
|
+
- **Generated interfaces** from protobuf definitions
|
|
558
|
+
- **All available methods** and their signatures
|
|
666
559
|
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
return readFileSync(infoPath, 'utf-8');
|
|
674
|
-
} catch (error) {
|
|
675
|
-
return \`Module documentation not found for \${modulePath}\`;
|
|
676
|
-
}
|
|
677
|
-
}
|
|
560
|
+
**Key files to understand**:
|
|
561
|
+
- \`src/${packageName}/index.ts\` - Main exports and available modules
|
|
562
|
+
- \`src/${packageName}/cosmos/\` - Cosmos SDK modules (bank, staking, gov, etc.)
|
|
563
|
+
- \`src/${packageName}/osmosis/\` - Osmosis-specific modules
|
|
564
|
+
- \`src/${packageName}/ibc/\` - Inter-blockchain communication
|
|
565
|
+
- \`src/${packageName}/README.md\` - Comprehensive documentation
|
|
678
566
|
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
*/
|
|
682
|
-
getModuleSchema(modulePath: string) {
|
|
683
|
-
// Return basic schema info for the module
|
|
684
|
-
return {
|
|
685
|
-
module: modulePath,
|
|
686
|
-
package: '${packageName}',
|
|
687
|
-
queries: ['getBalance', 'getAllBalances'],
|
|
688
|
-
mutations: ['send', 'delegate'],
|
|
689
|
-
types: ['Coin', 'MsgSend', 'MsgDelegate']
|
|
690
|
-
};
|
|
691
|
-
}
|
|
692
|
-
}
|
|
693
|
-
|
|
694
|
-
export const telescopeLoader = new TelescopeLoader();
|
|
695
|
-
`;
|
|
696
|
-
}
|
|
697
|
-
function generateComprehensivePrompts(mcpServerPath, packageName) {
|
|
698
|
-
// Generate codegen-usage.md
|
|
699
|
-
const codegenUsageContent = `# Codegen Usage Guide
|
|
567
|
+
### Production Examples: \`src/${packageName}-examples/\` Directory
|
|
568
|
+
Use these as **implementation patterns** and **logic reference**:
|
|
700
569
|
|
|
701
|
-
|
|
702
|
-
|
|
570
|
+
- **Real production code** showing how to use telescope functions
|
|
571
|
+
- **Best practices** for error handling and data processing
|
|
572
|
+
- **Complete workflows** for common blockchain operations
|
|
703
573
|
|
|
704
|
-
|
|
574
|
+
**⚠️ Important**: These examples may contain import/compilation errors since they reference the main codebase. **Focus on the logic and patterns** rather than copying code directly.
|
|
705
575
|
|
|
706
|
-
|
|
707
|
-
These are direct async functions that make RPC calls to blockchain nodes. Use these for:
|
|
708
|
-
- Server-side operations
|
|
709
|
-
- Node.js scripts
|
|
710
|
-
- Direct blockchain queries outside React
|
|
576
|
+
## Using the MCP Tool
|
|
711
577
|
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
import { getBalance } from '${packageName}/cosmos/bank/v1beta1/query.rpc.func';
|
|
715
|
-
import { send } from '${packageName}/cosmos/bank/v1beta1/tx.rpc.func';
|
|
716
|
-
\`\`\`
|
|
578
|
+
### Single Tool: \`use-${packageName}\`
|
|
579
|
+
This MCP server provides one tool that generates implementation guidance by:
|
|
717
580
|
|
|
718
|
-
**
|
|
581
|
+
1. **Analyzing your request** (task, chain, function type)
|
|
582
|
+
2. **Finding relevant examples** from \`${packageName}-examples/\`
|
|
583
|
+
3. **Providing step-by-step guidance** using telescope patterns
|
|
584
|
+
4. **Showing proper imports** and configuration
|
|
719
585
|
|
|
720
|
-
|
|
721
|
-
\`\`\`typescript
|
|
722
|
-
import { getBalance } from '${packageName}/cosmos/bank/v1beta1/query.rpc.func';
|
|
586
|
+
## Implementation Approach
|
|
723
587
|
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
address: "cosmos1...",
|
|
727
|
-
denom: "uatom"
|
|
728
|
-
});
|
|
588
|
+
### Step 1: Understand Telescope Structure
|
|
589
|
+
When implementing a function, first explore \`src/${packageName}/\` to understand:
|
|
729
590
|
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
}
|
|
736
|
-
console.error('Error fetching balance:', error);
|
|
737
|
-
return null;
|
|
738
|
-
}
|
|
591
|
+
\`\`\`typescript
|
|
592
|
+
// Example: For balance queries, look at:
|
|
593
|
+
// src/${packageName}/cosmos/bank/v1beta1/query.ts - Type definitions
|
|
594
|
+
// src/${packageName}/cosmos/bank/v1beta1/query.rpc.Query.ts - Query client
|
|
595
|
+
// src/${packageName}/cosmos/bank/v1beta1/query.rpc.func.ts - Direct functions
|
|
596
|
+
// src/${packageName}/cosmos/bank/v1beta1/query.rpc.react.ts - React hooks
|
|
739
597
|
\`\`\`
|
|
740
598
|
|
|
741
|
-
### 2
|
|
742
|
-
|
|
743
|
-
- Automatic caching and refetching
|
|
744
|
-
- Loading states
|
|
745
|
-
- Error handling
|
|
746
|
-
- Integration with React Query
|
|
599
|
+
### Step 2: Reference Production Examples
|
|
600
|
+
Look at \`${packageName}-examples/\` for implementation patterns:
|
|
747
601
|
|
|
748
|
-
**Import Pattern**:
|
|
749
602
|
\`\`\`typescript
|
|
750
|
-
|
|
751
|
-
|
|
603
|
+
// Example: useBalance.ts shows the pattern for:
|
|
604
|
+
// - Proper imports from telescope
|
|
605
|
+
// - Error handling approaches
|
|
606
|
+
// - Data transformation logic
|
|
607
|
+
// - Integration with React Query
|
|
608
|
+
|
|
609
|
+
// Focus on UNDERSTANDING the logic:
|
|
610
|
+
// - How RPC endpoints are configured
|
|
611
|
+
// - How parameters are validated
|
|
612
|
+
// - How responses are processed
|
|
613
|
+
// - How errors are handled
|
|
752
614
|
\`\`\`
|
|
753
615
|
|
|
754
|
-
|
|
616
|
+
### Step 3: Generate Your Implementation
|
|
617
|
+
Use the patterns from both directories to create your function:
|
|
755
618
|
|
|
756
|
-
### Import Chain Registry Data
|
|
757
619
|
\`\`\`typescript
|
|
758
|
-
|
|
620
|
+
// Your implementation should:
|
|
621
|
+
// 1. Use proper imports from the telescope codebase
|
|
622
|
+
// 2. Follow error handling patterns from examples
|
|
623
|
+
// 3. Include proper TypeScript types
|
|
624
|
+
// 4. Handle edge cases shown in examples
|
|
759
625
|
\`\`\`
|
|
760
626
|
|
|
761
|
-
|
|
762
|
-
\`\`\`typescript
|
|
763
|
-
// Define your target chain
|
|
764
|
-
export const defaultChainName = 'cosmos'; // or 'osmosis', 'injective', etc.
|
|
765
|
-
|
|
766
|
-
// Find chain info from registry
|
|
767
|
-
export const defaultChain = chains.find((chain) => chain.chainName === defaultChainName);
|
|
627
|
+
## Category of Functions in Telescope
|
|
768
628
|
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
## Detailed Examples Reference
|
|
629
|
+
### 1. **query.rpc.func.ts** - Direct Function Calls
|
|
630
|
+
- Server-side operations
|
|
631
|
+
- Node.js scripts
|
|
632
|
+
- Direct blockchain queries
|
|
774
633
|
|
|
775
|
-
###
|
|
776
|
-
|
|
634
|
+
### 2. **query.rpc.react.ts** - React Hooks
|
|
635
|
+
- Frontend applications
|
|
636
|
+
- Automatic caching and refetching
|
|
637
|
+
- Loading states and error handling
|
|
777
638
|
|
|
778
|
-
###
|
|
779
|
-
|
|
780
|
-
-
|
|
781
|
-
- Handling errors and returning proper MCP responses
|
|
782
|
-
- Working with blockchain data in MCP context
|
|
639
|
+
### 3. **tx.rpc.func.ts** - Transaction Functions
|
|
640
|
+
- Broadcasting transactions
|
|
641
|
+
- Message composition
|
|
783
642
|
|
|
784
|
-
|
|
643
|
+
### 4. **tx.rpc.react.ts** - Transaction Hooks
|
|
644
|
+
- Transaction broadcasting in React
|
|
645
|
+
- Transaction state management
|
|
785
646
|
|
|
786
|
-
##
|
|
647
|
+
## Chain Configuration Pattern
|
|
787
648
|
|
|
788
|
-
|
|
789
|
-
- **Use .rpc.func** for: Server-side scripts, CLI tools, backend services
|
|
790
|
-
- **Use .rpc.react** for: React applications, frontend components with state management
|
|
649
|
+
Always reference \`config-example.ts\` for proper setup:
|
|
791
650
|
|
|
792
|
-
### Error Handling Patterns
|
|
793
651
|
\`\`\`typescript
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
return null; // Handle account not found
|
|
801
|
-
}
|
|
802
|
-
throw error; // Re-throw other errors
|
|
803
|
-
}
|
|
652
|
+
import { assetLists, chains } from "@chain-registry/v2";
|
|
653
|
+
|
|
654
|
+
export const targetChainName = 'cosmos';
|
|
655
|
+
export const rpcEndpoint = 'https://cosmos-rpc.quickapi.com:443';
|
|
656
|
+
export const chain = chains.find((chain) => chain.chainName === targetChainName);
|
|
657
|
+
export const assetList = assetLists.find((assetList) => assetList.chainName === targetChainName);
|
|
804
658
|
\`\`\`
|
|
659
|
+
|
|
660
|
+
## Important Guidelines
|
|
661
|
+
|
|
662
|
+
### When Using Examples
|
|
663
|
+
- **Study the logic**, don't copy/paste directly
|
|
664
|
+
- **Understand the patterns** for imports and usage
|
|
665
|
+
- **Learn from error handling** approaches
|
|
666
|
+
- **Adapt the structure** to your specific needs
|
|
667
|
+
|
|
668
|
+
### When Using Telescope Codebase
|
|
669
|
+
- **Browse the generated files** to understand available methods
|
|
670
|
+
- **Check type definitions** for proper parameter structures
|
|
671
|
+
- **Look at client implementations** for usage patterns
|
|
672
|
+
- **Reference documentation** in README.md files
|
|
673
|
+
|
|
674
|
+
### Best Practices
|
|
675
|
+
1. Always include comprehensive error handling
|
|
676
|
+
2. Validate input parameters before making calls
|
|
677
|
+
3. Convert base units to human-readable amounts when needed
|
|
678
|
+
4. Use proper TypeScript types from telescope
|
|
679
|
+
5. Test your implementations thoroughly
|
|
805
680
|
`;
|
|
806
681
|
writeFileSync(join(mcpServerPath, 'src', 'prompts', 'codegen-usage.md'), codegenUsageContent);
|
|
807
682
|
// Generate agent-guidelines.md
|
|
@@ -963,17 +838,16 @@ function generateTelescopeExamples(mcpServerPath, packageName) {
|
|
|
963
838
|
content: `import { assetLists, chains } from "@chain-registry/v2";
|
|
964
839
|
|
|
965
840
|
/**
|
|
841
|
+
* Chain configuration example
|
|
966
842
|
* mainnet: 'cosmos'
|
|
967
|
-
* testnet: 'cosmoshub-testnet'
|
|
843
|
+
* testnet: 'cosmoshub-testnet'
|
|
968
844
|
* mainnet rpc: 'https://cosmos-rpc.quickapi.com:443'
|
|
969
845
|
* testnet rpc: 'https://rpc.testnet.cosmos.network:443'
|
|
970
846
|
*/
|
|
971
|
-
export const
|
|
972
|
-
export const
|
|
973
|
-
|
|
974
|
-
export const
|
|
975
|
-
|
|
976
|
-
export const defaultAssetList = assetLists.find((assetList) => assetList.chainName === defaultChainName)
|
|
847
|
+
export const targetChainName = 'cosmos';
|
|
848
|
+
export const rpcEndpoint = 'https://cosmos-rpc.quickapi.com:443';
|
|
849
|
+
export const chain = chains.find((chain) => chain.chainName === targetChainName);
|
|
850
|
+
export const assetList = assetLists.find((assetList) => assetList.chainName === targetChainName);
|
|
977
851
|
`
|
|
978
852
|
},
|
|
979
853
|
{
|
|
@@ -1844,6 +1718,6 @@ export const useTotalAssets = (chainName: string) => {
|
|
|
1844
1718
|
];
|
|
1845
1719
|
// Write all example files
|
|
1846
1720
|
exampleFiles.forEach(({ name, content }) => {
|
|
1847
|
-
writeFileSync(join(mcpServerPath, 'src',
|
|
1721
|
+
writeFileSync(join(mcpServerPath, 'src', `${packageName}-examples`, name), content);
|
|
1848
1722
|
});
|
|
1849
1723
|
}
|
|
@@ -111,7 +111,7 @@ function getTypesForPackage(builder, packageName) {
|
|
|
111
111
|
return uniqueTypes.sort((a, b) => a.name.localeCompare(b.name));
|
|
112
112
|
}
|
|
113
113
|
export const plugin = (builder) => {
|
|
114
|
-
if (!builder.options
|
|
114
|
+
if (!builder.options?.readme?.enabled && !builder.options?.mcpServer?.enabled) {
|
|
115
115
|
return;
|
|
116
116
|
}
|
|
117
117
|
const readmePath = join(builder.outPath, "README.md");
|