@kya-os/create-mcpi-app 1.7.34 → 1.7.36

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.
@@ -894,7 +894,7 @@ export function getRuntimeConfig(env: CloudflareEnv): CloudflareRuntimeConfig {
894
894
  // Create main index.ts using McpAgent with MCP-I runtime
895
895
  const indexContent = `import { McpAgent } from "agents/mcp";
896
896
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
897
- import { createCloudflareRuntime, type CloudflareEnv, KVProofArchive, type DetachedProof, createOAuthCallbackHandler, CloudflareRuntime } from "@kya-os/mcp-i-cloudflare";
897
+ import { createCloudflareRuntime, type CloudflareEnv, KVProofArchive, type DetachedProof, createOAuthCallbackHandler, CloudflareRuntime, type HonoContext } from "@kya-os/mcp-i-cloudflare";
898
898
  import { DelegationRequiredError } from "@kya-os/mcp-i-core";
899
899
  import type { ToolProtectionService } from "@kya-os/mcp-i-core";
900
900
  import { Hono } from "hono";
@@ -1700,7 +1700,8 @@ app.get('/oauth/callback', async (c) => {
1700
1700
  autoClose: true,
1701
1701
  autoCloseDelay: 5000
1702
1702
  });
1703
- return await handler(c as any);
1703
+ // Cast to HonoContext - Hono's context implements all required properties
1704
+ return await handler(c as unknown as HonoContext);
1704
1705
  });
1705
1706
 
1706
1707
  // Multi-instance DO routing using McpAgent's getInstanceId() override
@@ -1803,23 +1804,22 @@ XMCP_I_SESSION_TTL = "1800"
1803
1804
 
1804
1805
  # AgentShield Integration (https://kya.vouched.id)
1805
1806
  AGENTSHIELD_API_URL = "https://kya.vouched.id"
1806
- # AGENTSHIELD_API_KEY - MUST be declared here for .dev.vars to work
1807
- # Development: Values in .dev.vars will override this empty string
1808
- # Production: Use wrangler secret put AGENTSHIELD_API_KEY
1809
- AGENTSHIELD_API_KEY = ""
1810
1807
  # AGENTSHIELD_PROJECT_ID - Your project ID from AgentShield dashboard (e.g., "batman-txh0ae")
1811
1808
  # Required for project-scoped tool protection configuration (recommended)
1812
1809
  # Find it in your dashboard URL: https://kya.vouched.id/dashboard/projects/{PROJECT_ID}
1813
1810
  # Or in your project settings
1814
- # This is not sensitive, so it's safe to keep a value here if provided
1811
+ # This is not sensitive, so it's safe to keep a value here
1815
1812
  AGENTSHIELD_PROJECT_ID = "${projectId || ""}"
1816
- # ADMIN_API_KEY - Used for protected admin endpoints (e.g., /admin/clear-cache)
1817
- # Set to same value as AGENTSHIELD_API_KEY by default
1818
- # Development: Values in .dev.vars will override this empty string
1819
- # Production: Use wrangler secret put ADMIN_API_KEY
1820
- ADMIN_API_KEY = ""
1821
1813
  MCPI_ENV = "development"
1822
1814
 
1815
+ # Secrets (NOT declared here - see instructions below)
1816
+ # For local development: Add secrets to .dev.vars file
1817
+ # For production: Use wrangler secret put COMMAND_NAME
1818
+ # $ wrangler secret put MCP_IDENTITY_PRIVATE_KEY
1819
+ # $ wrangler secret put AGENTSHIELD_API_KEY
1820
+ # $ wrangler secret put ADMIN_API_KEY
1821
+ # Note: .dev.vars is git-ignored and contains actual secret values for local dev
1822
+
1823
1823
  # Optional: MCP Server URL for tool discovery
1824
1824
  # Uncomment to explicitly set your MCP server URL (auto-detected if not set)
1825
1825
  # MCP_SERVER_URL = "https://your-worker.workers.dev/mcp"
@@ -1846,11 +1846,12 @@ MCPI_ENV = "development"
1846
1846
  # Agent DID (public identifier - safe to commit)
1847
1847
  MCP_IDENTITY_AGENT_DID = "${identity.did}"
1848
1848
 
1849
- # Identity keys - MUST be declared here for .dev.vars to work!
1850
- # Development: Values in .dev.vars will override these empty strings
1851
- # Production: Use wrangler secret put to set these
1852
- MCP_IDENTITY_PRIVATE_KEY = ""
1853
- MCP_IDENTITY_PUBLIC_KEY = ""
1849
+ # Public identity key (safe to commit - not sensitive)
1850
+ MCP_IDENTITY_PUBLIC_KEY = "${identity.publicKey}"
1851
+
1852
+ # Private identity key (SECRET - NOT declared here)
1853
+ # For local development: Add to .dev.vars file
1854
+ # For production: Use wrangler secret put MCP_IDENTITY_PRIVATE_KEY
1854
1855
 
1855
1856
  # ALLOWED_ORIGINS for CORS (update for production)
1856
1857
  ALLOWED_ORIGINS = "https://claude.ai,https://app.anthropic.com"
@@ -1861,36 +1862,26 @@ DO_SHARD_COUNT = "10" # Number of shards if using shard strategy
1861
1862
 
1862
1863
  `;
1863
1864
 
1864
- // Update existing values in wrangler.toml if they already exist
1865
- // This handles the case where variables were added by the initial template
1866
- // IMPORTANT: Secrets are always kept as empty strings in wrangler.toml
1867
- // Actual values go in .dev.vars for local dev, wrangler secret put for production
1865
+ // Remove any secret declarations from [vars] (they should not be here)
1866
+ // Secrets go in .dev.vars for local dev, wrangler secret put for production
1867
+ wranglerTomlContent = wranglerTomlContent.replace(
1868
+ /^\s*MCP_IDENTITY_PRIVATE_KEY\s*=.*$/gm,
1869
+ `# MCP_IDENTITY_PRIVATE_KEY - SECRET (not declared here, see .dev.vars or wrangler secret put)`
1870
+ );
1871
+ wranglerTomlContent = wranglerTomlContent.replace(
1872
+ /^\s*AGENTSHIELD_API_KEY\s*=.*$/gm,
1873
+ `# AGENTSHIELD_API_KEY - SECRET (not declared here, see .dev.vars or wrangler secret put)`
1874
+ );
1875
+ wranglerTomlContent = wranglerTomlContent.replace(
1876
+ /^\s*ADMIN_API_KEY\s*=.*$/gm,
1877
+ `# ADMIN_API_KEY - SECRET (not declared here, see .dev.vars or wrangler secret put)`
1878
+ );
1868
1879
 
1869
- // Ensure identity keys are empty strings (not actual values)
1870
- if (/MCP_IDENTITY_PRIVATE_KEY\s*=/.test(wranglerTomlContent)) {
1871
- wranglerTomlContent = wranglerTomlContent.replace(
1872
- /MCP_IDENTITY_PRIVATE_KEY\s*=\s*"[^"]*"/,
1873
- `MCP_IDENTITY_PRIVATE_KEY = ""`
1874
- );
1875
- }
1880
+ // Update public key if it exists (safe to keep in [vars])
1876
1881
  if (/MCP_IDENTITY_PUBLIC_KEY\s*=/.test(wranglerTomlContent)) {
1877
1882
  wranglerTomlContent = wranglerTomlContent.replace(
1878
1883
  /MCP_IDENTITY_PUBLIC_KEY\s*=\s*"[^"]*"/,
1879
- `MCP_IDENTITY_PUBLIC_KEY = ""`
1880
- );
1881
- }
1882
-
1883
- // Ensure API keys are empty strings (not actual values)
1884
- if (/AGENTSHIELD_API_KEY\s*=/.test(wranglerTomlContent)) {
1885
- wranglerTomlContent = wranglerTomlContent.replace(
1886
- /AGENTSHIELD_API_KEY\s*=\s*"[^"]*"/,
1887
- `AGENTSHIELD_API_KEY = ""`
1888
- );
1889
- }
1890
- if (/ADMIN_API_KEY\s*=/.test(wranglerTomlContent)) {
1891
- wranglerTomlContent = wranglerTomlContent.replace(
1892
- /ADMIN_API_KEY\s*=\s*"[^"]*"/,
1893
- `ADMIN_API_KEY = ""`
1884
+ `MCP_IDENTITY_PUBLIC_KEY = "${identity.publicKey}"`
1894
1885
  );
1895
1886
  }
1896
1887
 
@@ -1906,82 +1897,21 @@ DO_SHARD_COUNT = "10" # Number of shards if using shard strategy
1906
1897
  );
1907
1898
  }
1908
1899
 
1909
- // Check if API key variables already exist in wrangler.toml
1910
- // (They may have been added by the initial template)
1911
- const hasAgentshieldApiKey = /AGENTSHIELD_API_KEY\s*=/.test(
1912
- wranglerTomlContent
1913
- );
1914
- const hasAgentshieldProjectId = /AGENTSHIELD_PROJECT_ID\s*=/.test(
1915
- wranglerTomlContent
1916
- );
1917
- const hasAdminApiKey = /ADMIN_API_KEY\s*=/.test(wranglerTomlContent);
1900
+ // Check if non-secret variables already exist in wrangler.toml
1918
1901
  const hasIdentityDid = /MCP_IDENTITY_AGENT_DID\s*=/.test(
1919
1902
  wranglerTomlContent
1920
1903
  );
1921
- const hasIdentityPrivateKey = /MCP_IDENTITY_PRIVATE_KEY\s*=/.test(
1922
- wranglerTomlContent
1923
- );
1924
1904
  const hasIdentityPublicKey = /MCP_IDENTITY_PUBLIC_KEY\s*=/.test(
1925
1905
  wranglerTomlContent
1926
1906
  );
1927
1907
 
1928
- // Build API key declarations only for variables that don't already exist
1929
- // Cloudflare Workers REQUIRE variables to be declared in [vars] for .dev.vars to work
1930
- const apiKeyVarsParts: string[] = [];
1931
-
1932
- if (
1933
- !hasAgentshieldApiKey ||
1934
- !hasAgentshieldProjectId ||
1935
- !hasAdminApiKey
1936
- ) {
1937
- apiKeyVarsParts.push(
1938
- `# API keys - MUST be declared here for .dev.vars to work!`
1939
- );
1940
- apiKeyVarsParts.push(
1941
- `# Development: Values in .dev.vars will override these empty strings`
1942
- );
1943
- apiKeyVarsParts.push(
1944
- `# Production: Use wrangler secret put to set these`
1945
- );
1946
- }
1947
-
1948
- if (!hasAgentshieldApiKey) {
1949
- apiKeyVarsParts.push(`AGENTSHIELD_API_KEY = ""`);
1950
- }
1951
- if (!hasAdminApiKey) {
1952
- apiKeyVarsParts.push(`ADMIN_API_KEY = ""`);
1953
- }
1954
- // Only add AGENTSHIELD_PROJECT_ID if it doesn't exist
1955
- // If projectId is provided, it will be set above (lines 1897-1907)
1956
- // If not provided, we still need to declare it for .dev.vars to work
1957
- if (!hasAgentshieldProjectId) {
1958
- apiKeyVarsParts.push(
1959
- `AGENTSHIELD_PROJECT_ID = "${projectId || ""}"`
1960
- );
1961
- }
1962
-
1963
- const apiKeyVars =
1964
- apiKeyVarsParts.length > 0
1965
- ? `\n${apiKeyVarsParts.join("\n")}\n`
1966
- : "";
1967
-
1968
- // Only insert identity vars and API key vars if they don't already exist in [vars]
1969
- // If they already exist, we've already updated them above to ensure they're empty strings
1970
- // Note: API keys are already in initial template, so we mainly check for identity vars
1971
- // But we also check for API keys in case they were removed from template
1972
- const needsInsertion =
1973
- !hasIdentityDid ||
1974
- !hasIdentityPrivateKey ||
1975
- !hasIdentityPublicKey ||
1976
- (!hasAgentshieldApiKey && apiKeyVarsParts.length > 0) ||
1977
- (!hasAdminApiKey && apiKeyVarsParts.length > 0) ||
1978
- (!hasAgentshieldProjectId && apiKeyVarsParts.length > 0);
1908
+ // Only insert identity vars if they don't already exist
1909
+ const needsInsertion = !hasIdentityDid || !hasIdentityPublicKey;
1979
1910
 
1980
1911
  if (needsInsertion) {
1981
1912
  wranglerTomlContent =
1982
1913
  wranglerTomlContent.slice(0, insertPosition) +
1983
1914
  identityVars +
1984
- apiKeyVars +
1985
1915
  wranglerTomlContent.slice(insertPosition);
1986
1916
  }
1987
1917
 
@@ -1989,25 +1919,24 @@ DO_SHARD_COUNT = "10" # Number of shards if using shard strategy
1989
1919
  fs.writeFileSync(wranglerPath, wranglerTomlContent);
1990
1920
 
1991
1921
  // Create .dev.vars file for local development (git-ignored)
1922
+ // Only contains SECRETS (not public keys or project IDs)
1992
1923
  const devVarsPath = path.join(projectPath, ".dev.vars");
1993
1924
  const devVarsContent = `# Local development secrets (DO NOT COMMIT)
1994
1925
  # This file is git-ignored and contains sensitive data
1995
1926
  #
1996
1927
  # HOW IT WORKS:
1997
- # 1. Variables are declared in wrangler.toml [vars] as empty strings
1998
- # 2. This file (.dev.vars) overrides them for local development
1928
+ # 1. Secrets are NOT declared in wrangler.toml [vars] (avoids conflicts)
1929
+ # 2. This file (.dev.vars) provides secrets for local development
1999
1930
  # 3. Production uses: wrangler secret put VARIABLE_NAME
1931
+ #
1932
+ # Non-secrets (MCP_IDENTITY_PUBLIC_KEY, AGENTSHIELD_PROJECT_ID) are in wrangler.toml
2000
1933
 
2001
- # Identity keys (generated by create-mcpi-app)
1934
+ # Private identity key (generated by create-mcpi-app)
2002
1935
  MCP_IDENTITY_PRIVATE_KEY="${identity.privateKey}"
2003
- MCP_IDENTITY_PUBLIC_KEY="${identity.publicKey}"
2004
1936
 
2005
1937
  # AgentShield API key (get from https://kya.vouched.id/dashboard)
2006
1938
  AGENTSHIELD_API_KEY="${apikey || ""}"${apikey ? " # Provided via --apikey flag" : ""}
2007
1939
 
2008
- # AgentShield Project ID (from dashboard URL: /dashboard/projects/{PROJECT_ID})
2009
- AGENTSHIELD_PROJECT_ID="${projectId || ""}"${projectId ? " # Provided via --project flag" : ""}
2010
-
2011
1940
  # Admin API key for protected endpoints (set to same value as AGENTSHIELD_API_KEY)
2012
1941
  ADMIN_API_KEY="${apikey || ""}"${apikey ? " # Set to same value as AGENTSHIELD_API_KEY" : ""}
2013
1942
  `;
@@ -2020,15 +1949,17 @@ ADMIN_API_KEY="${apikey || ""}"${apikey ? " # Set to same value as AGENTSHIELD_
2020
1949
  );
2021
1950
  const devVarsExampleContent = `# Copy this file to .dev.vars and fill in your values
2022
1951
  # DO NOT commit .dev.vars to version control
1952
+ #
1953
+ # NOTE: Only secrets go here. Non-secrets (MCP_IDENTITY_PUBLIC_KEY, AGENTSHIELD_PROJECT_ID)
1954
+ # are in wrangler.toml [vars] and can be committed safely.
2023
1955
 
2024
- # Identity keys (generate with: npx @kya-os/create-mcpi-app regenerate-identity)
1956
+ # Private identity key (generate with: npx @kya-os/create-mcpi-app regenerate-identity)
2025
1957
  MCP_IDENTITY_PRIVATE_KEY="your-private-key-here"
2026
- MCP_IDENTITY_PUBLIC_KEY="your-public-key-here"
2027
1958
 
2028
- # AgentShield API key (get from https://agentshield.ai)
1959
+ # AgentShield API key (get from https://kya.vouched.id/dashboard)
2029
1960
  AGENTSHIELD_API_KEY="your-api-key-here"
2030
1961
 
2031
- # Admin API key for protected endpoints
1962
+ # Admin API key for protected endpoints (set to same value as AGENTSHIELD_API_KEY)
2032
1963
  ADMIN_API_KEY="your-admin-key-here"
2033
1964
  `;
2034
1965
  fs.writeFileSync(devVarsExamplePath, devVarsExampleContent);
@@ -2046,18 +1977,22 @@ ADMIN_API_KEY="your-admin-key-here"
2046
1977
  console.log();
2047
1978
  console.log(chalk.yellow("🔒 Production Security:"));
2048
1979
  console.log(
2049
- chalk.dim(" Set secrets using wrangler (never commit them):")
1980
+ chalk.dim(" Secrets are NOT in wrangler.toml (cleaner approach)")
2050
1981
  );
2051
1982
  console.log(
2052
- chalk.cyan(" $ wrangler secret put MCP_IDENTITY_PRIVATE_KEY")
1983
+ chalk.dim(" For production, set secrets using wrangler:")
2053
1984
  );
2054
1985
  console.log(
2055
- chalk.cyan(" $ wrangler secret put MCP_IDENTITY_PUBLIC_KEY")
1986
+ chalk.cyan(" $ wrangler secret put MCP_IDENTITY_PRIVATE_KEY")
2056
1987
  );
2057
1988
  console.log(
2058
- chalk.cyan(" $ wrangler secret put AGENTSHIELD_API_KEY")
1989
+ chalk.cyan(" $ wrangler secret put AGENTSHIELD_API_KEY")
1990
+ );
1991
+ console.log(chalk.cyan(" $ wrangler secret put ADMIN_API_KEY"));
1992
+ console.log();
1993
+ console.log(
1994
+ chalk.dim(" Tip: Copy values from .dev.vars when prompted")
2059
1995
  );
2060
- console.log(chalk.cyan(" $ wrangler secret put ADMIN_API_KEY"));
2061
1996
  console.log();
2062
1997
  }
2063
1998
  } catch (error: any) {
@@ -2181,6 +2116,22 @@ ${packageManager === "npm" ? "npm run" : packageManager} dev
2181
2116
 
2182
2117
  ### 4. Deploy
2183
2118
 
2119
+ #### Production Deployment
2120
+
2121
+ Secrets are **not** declared in \`wrangler.toml\` to avoid conflicts. Set them using:
2122
+
2123
+ \`\`\`bash
2124
+ wrangler secret put MCP_IDENTITY_PRIVATE_KEY
2125
+ wrangler secret put AGENTSHIELD_API_KEY
2126
+ wrangler secret put ADMIN_API_KEY
2127
+ \`\`\`
2128
+
2129
+ **Tip:** Copy values from your \`.dev.vars\` file when prompted.
2130
+
2131
+ **Note:** \`MCP_IDENTITY_PUBLIC_KEY\` and \`AGENTSHIELD_PROJECT_ID\` are not secrets and are already in \`wrangler.toml\` with values.
2132
+
2133
+ Now deploy:
2134
+
2184
2135
  \`\`\`bash
2185
2136
  ${packageManager === "npm" ? "npm run" : packageManager} deploy
2186
2137
  \`\`\`
@@ -2438,3 +2389,4 @@ Or simply don't configure the \`AGENTSHIELD_API_KEY\` environment variable.
2438
2389
  throw error;
2439
2390
  }
2440
2391
  }
2392
+
@@ -1,3 +1,4 @@
1
+ /// <reference types="@cloudflare/workers-types" />
1
2
  import { McpAgent } from "agents/mcp";
2
3
  import { Hono } from "hono";
3
4
  import { cors } from "hono/cors";
@@ -2,21 +2,15 @@
2
2
  "compilerOptions": {
3
3
  "target": "ES2022",
4
4
  "module": "ES2022",
5
- "lib": [
6
- "ES2022"
7
- ],
8
- "types": [
9
- "@cloudflare/workers-types"
10
- ],
5
+ "lib": ["ES2022"],
11
6
  "moduleResolution": "bundler",
12
7
  "resolveJsonModule": true,
13
8
  "allowSyntheticDefaultImports": true,
14
9
  "esModuleInterop": true,
15
10
  "strict": true,
16
11
  "skipLibCheck": true,
17
- "forceConsistentCasingInFileNames": true
12
+ "forceConsistentCasingInFileNames": true,
13
+ "noEmit": true
18
14
  },
19
- "include": [
20
- "src/**/*"
21
- ]
15
+ "include": ["src/**/*", "tests/**/*"]
22
16
  }