@@ -2,6 +2,7 @@ import type { Server } from "@modelcontextprotocol/sdk/server/index.js";
22import { z } from "zod" ;
33import type { SuggestedAction } from "../errors.js" ;
44import { classifyError , formatClassifiedError } from "../errors.js" ;
5+ import { getRpcResolver } from "../rpc/resolver.js" ;
56import type { KeplrPlugin } from "./types.js" ;
67
78// ─── HTTP Client ─────────────────────────────────────────────────────
@@ -193,17 +194,28 @@ const keplrRpcPlugin: KeplrPlugin = {
193194 name : "keplr-rpc" ,
194195
195196 register ( server , _store ) {
197+ /** Resolve API key: explicit param → configured key (env / config file). */
198+ const resolveApiKey = ( explicit ?: string ) : string => {
199+ const key = explicit || getRpcResolver ( ) . apiKey ;
200+ if ( ! key ) {
201+ throw new KeplrApiError ( 403 , "No API key configured" ) ;
202+ }
203+ return key ;
204+ } ;
205+
196206 // ── keplr_api_configure_key ────────────────────────────────────────
197207 server . registerTool (
198208 "keplr_api_configure_key" ,
199209 {
200210 description :
201- "Configure a Keplr Infra API key. Validates the key, then saves it to the MCP configuration file " +
211+ "Configure a Keplr Infra API key (get one at https://api.keplr.app) . Validates the key, then saves it to the MCP configuration file " +
202212 "based on the detected client. Restart required after configuration." ,
203213 inputSchema : {
204214 apiKey : z
205215 . string ( )
206- . describe ( "Keplr Infra API key (starts with 'keplr_')" ) ,
216+ . describe (
217+ "Keplr Infra API key from https://api.keplr.app (starts with 'keplr_')" ,
218+ ) ,
207219 scope : z
208220 . enum ( [ "user" , "project" ] )
209221 . optional ( )
@@ -482,12 +494,18 @@ const keplrRpcPlugin: KeplrPlugin = {
482494 {
483495 description : "Validate an existing Keplr Infra API key" ,
484496 inputSchema : {
485- apiKey : z . string ( ) . describe ( "API key to validate" ) ,
497+ apiKey : z
498+ . string ( )
499+ . optional ( )
500+ . describe (
501+ "API key to validate (auto-detected from configured key if omitted)" ,
502+ ) ,
486503 } ,
487504 annotations : { readOnlyHint : true } ,
488505 } ,
489- async ( { apiKey } ) => {
506+ async ( { apiKey : explicitKey } ) => {
490507 try {
508+ const apiKey = resolveApiKey ( explicitKey ) ;
491509 const data = await keplrApiFetch < Record < string , unknown > > ( {
492510 method : "POST" ,
493511 path : "/v1/keys/validate" ,
@@ -536,12 +554,16 @@ const keplrRpcPlugin: KeplrPlugin = {
536554 {
537555 description : "Get a Stripe payment link to add credits" ,
538556 inputSchema : {
539- apiKey : z . string ( ) . describe ( "API key" ) ,
557+ apiKey : z
558+ . string ( )
559+ . optional ( )
560+ . describe ( "API key (auto-detected from configured key if omitted)" ) ,
540561 } ,
541562 annotations : { readOnlyHint : true } ,
542563 } ,
543- async ( { apiKey } ) => {
564+ async ( { apiKey : explicitKey } ) => {
544565 try {
566+ const apiKey = resolveApiKey ( explicitKey ) ;
545567 const data = await keplrApiFetch < Record < string , unknown > > ( {
546568 method : "GET" ,
547569 path : "/v1/credits/payment-link" ,
@@ -582,12 +604,16 @@ const keplrRpcPlugin: KeplrPlugin = {
582604 description :
583605 "Get usage summary (balance, requests, credits, per-chain breakdown)" ,
584606 inputSchema : {
585- apiKey : z . string ( ) . describe ( "API key" ) ,
607+ apiKey : z
608+ . string ( )
609+ . optional ( )
610+ . describe ( "API key (auto-detected from configured key if omitted)" ) ,
586611 } ,
587612 annotations : { readOnlyHint : true } ,
588613 } ,
589- async ( { apiKey } ) => {
614+ async ( { apiKey : explicitKey } ) => {
590615 try {
616+ const apiKey = resolveApiKey ( explicitKey ) ;
591617 const raw = await keplrApiFetch < Record < string , unknown > > ( {
592618 method : "GET" ,
593619 path : `/v1/usage/${ apiKey } /summary` ,
@@ -633,7 +659,10 @@ const keplrRpcPlugin: KeplrPlugin = {
633659 description :
634660 "Get usage history with optional date/chain/endpoint filters" ,
635661 inputSchema : {
636- apiKey : z . string ( ) . describe ( "API key" ) ,
662+ apiKey : z
663+ . string ( )
664+ . optional ( )
665+ . describe ( "API key (auto-detected from configured key if omitted)" ) ,
637666 startDate : z . string ( ) . optional ( ) . describe ( "Start date (ISO format)" ) ,
638667 endDate : z . string ( ) . optional ( ) . describe ( "End date (ISO format)" ) ,
639668 chain : z . string ( ) . optional ( ) . describe ( "Filter by chain ID" ) ,
@@ -644,8 +673,15 @@ const keplrRpcPlugin: KeplrPlugin = {
644673 } ,
645674 annotations : { readOnlyHint : true } ,
646675 } ,
647- async ( { apiKey, startDate, endDate, chain, endpointType } ) => {
676+ async ( {
677+ apiKey : explicitKey ,
678+ startDate,
679+ endDate,
680+ chain,
681+ endpointType,
682+ } ) => {
648683 try {
684+ const apiKey = resolveApiKey ( explicitKey ) ;
649685 const query : Record < string , string > = { clientType : "keplr-mcp" } ;
650686 if ( startDate ) query . startDate = startDate ;
651687 if ( endDate ) query . endDate = endDate ;
@@ -689,12 +725,16 @@ const keplrRpcPlugin: KeplrPlugin = {
689725 "Get Keplr Infra credit transaction history (top-ups, adjustments). " +
690726 "Use this after payment to verify the exact credit amount added instead of comparing usage summaries." ,
691727 inputSchema : {
692- apiKey : z . string ( ) . describe ( "API key" ) ,
728+ apiKey : z
729+ . string ( )
730+ . optional ( )
731+ . describe ( "API key (auto-detected from configured key if omitted)" ) ,
693732 } ,
694733 annotations : { readOnlyHint : true } ,
695734 } ,
696- async ( { apiKey } ) => {
735+ async ( { apiKey : explicitKey } ) => {
697736 try {
737+ const apiKey = resolveApiKey ( explicitKey ) ;
698738 const raw = await keplrApiFetch < Record < string , unknown > > ( {
699739 method : "GET" ,
700740 path : `/v1/credits/${ apiKey } /history` ,
0 commit comments