11import { InspectorConfig } from "@/lib/configurationTypes" ;
2- import { DEFAULT_MCP_PROXY_LISTEN_PORT } from "@/lib/constants" ;
2+ import {
3+ DEFAULT_MCP_PROXY_LISTEN_PORT ,
4+ DEFAULT_INSPECTOR_CONFIG ,
5+ } from "@/lib/constants" ;
36
47export const getMCPProxyAddress = ( config : InspectorConfig ) : string => {
58 const proxyFullAddress = config . MCP_PROXY_FULL_ADDRESS . value as string ;
@@ -24,3 +27,100 @@ export const getMCPServerRequestMaxTotalTimeout = (
2427) : number => {
2528 return config . MCP_REQUEST_MAX_TOTAL_TIMEOUT . value as number ;
2629} ;
30+
31+ const getSearchParam = ( key : string ) : string | null => {
32+ try {
33+ const url = new URL ( window . location . href ) ;
34+ return url . searchParams . get ( key ) ;
35+ } catch {
36+ return null ;
37+ }
38+ } ;
39+
40+ export const getInitialTransportType = ( ) :
41+ | "stdio"
42+ | "sse"
43+ | "streamable-http" => {
44+ const param = getSearchParam ( "transport" ) ;
45+ if ( param === "stdio" || param === "sse" || param === "streamable-http" ) {
46+ return param ;
47+ }
48+ return (
49+ ( localStorage . getItem ( "lastTransportType" ) as
50+ | "stdio"
51+ | "sse"
52+ | "streamable-http" ) || "stdio"
53+ ) ;
54+ } ;
55+
56+ export const getInitialSseUrl = ( ) : string => {
57+ const param = getSearchParam ( "serverUrl" ) ;
58+ if ( param ) return param ;
59+ return localStorage . getItem ( "lastSseUrl" ) || "http://localhost:3001/sse" ;
60+ } ;
61+
62+ export const getInitialCommand = ( ) : string => {
63+ const param = getSearchParam ( "serverCommand" ) ;
64+ if ( param ) return param ;
65+ return localStorage . getItem ( "lastCommand" ) || "mcp-server-everything" ;
66+ } ;
67+
68+ export const getInitialArgs = ( ) : string => {
69+ const param = getSearchParam ( "serverArgs" ) ;
70+ if ( param ) return param ;
71+ return localStorage . getItem ( "lastArgs" ) || "" ;
72+ } ;
73+
74+ // Returns a map of config key -> value from query params if present
75+ export const getConfigOverridesFromQueryParams = (
76+ defaultConfig : InspectorConfig ,
77+ ) : Partial < InspectorConfig > => {
78+ const url = new URL ( window . location . href ) ;
79+ const overrides : Partial < InspectorConfig > = { } ;
80+ for ( const key of Object . keys ( defaultConfig ) ) {
81+ const param = url . searchParams . get ( key ) ;
82+ if ( param !== null ) {
83+ // Try to coerce to correct type based on default value
84+ const defaultValue = defaultConfig [ key as keyof InspectorConfig ] . value ;
85+ let value : string | number | boolean = param ;
86+ if ( typeof defaultValue === "number" ) {
87+ value = Number ( param ) ;
88+ } else if ( typeof defaultValue === "boolean" ) {
89+ value = param === "true" ;
90+ }
91+ overrides [ key as keyof InspectorConfig ] = {
92+ ...defaultConfig [ key as keyof InspectorConfig ] ,
93+ value,
94+ } ;
95+ }
96+ }
97+ return overrides ;
98+ } ;
99+
100+ export const initializeInspectorConfig = (
101+ localStorageKey : string ,
102+ ) : InspectorConfig => {
103+ const savedConfig = localStorage . getItem ( localStorageKey ) ;
104+ let baseConfig : InspectorConfig ;
105+ if ( savedConfig ) {
106+ // merge default config with saved config
107+ const mergedConfig = {
108+ ...DEFAULT_INSPECTOR_CONFIG ,
109+ ...JSON . parse ( savedConfig ) ,
110+ } as InspectorConfig ;
111+
112+ // update description of keys to match the new description (in case of any updates to the default config description)
113+ for ( const [ key , value ] of Object . entries ( mergedConfig ) ) {
114+ mergedConfig [ key as keyof InspectorConfig ] = {
115+ ...value ,
116+ label : DEFAULT_INSPECTOR_CONFIG [ key as keyof InspectorConfig ] . label ,
117+ } ;
118+ }
119+ baseConfig = mergedConfig ;
120+ } else {
121+ baseConfig = DEFAULT_INSPECTOR_CONFIG ;
122+ }
123+ // Apply query param overrides
124+ const overrides = getConfigOverridesFromQueryParams ( DEFAULT_INSPECTOR_CONFIG ) ;
125+ return { ...baseConfig , ...overrides } ;
126+ } ;
0 commit comments