Skip to content

Commit ef12c9e

Browse files
docs: update CLAUDE.md with ValTown context and fix repository URLs (#2)
* feat: add remote HTTP transport for ValTown deployment - Modify registerTools() to accept excludeCli parameter - Update config.ts for remote mode with header-based authentication - Create index.ts HTTP entry point with streamable transport - Remove backend directory and setup ValTown project structure - Add .vtignore to exclude local files from deployment - Update Config type to support null apiToken for remote mode * feat: complete remote HTTP MCP server implementation - Implement HTTP transport with JSON-RPC protocol handling - Add missing CLI utility functions as placeholders for remote mode - Fix transport interface and MCP server integration - Support initialize, tools/list, tools/call, prompts/list, prompts/get methods - Add proper CORS headers and error handling - Complete all planned phases for ValTown deployment * fix: update CLI function calls to match interface signatures 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * feat: migrate from deno.json import map to direct npm imports - Remove import map from deno.json to support ValTown deployment - Update all TypeScript files to use direct npm imports (npm:zod, npm:@modelcontextprotocol/sdk) - Maintains compatibility with both CLI and ValTown environments - All tools now use direct imports instead of import map resolution 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * feat: add GET endpoint for MCP server info - Add GET / endpoint that returns server information - Include server name, version, description, and available endpoints - Update CORS to allow GET requests - Show 'Configuration endpoint coming soon' message 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * fix: use native Response for GET endpoint - Replace c.json() with new Response() for better ValTown compatibility - Manually set Content-Type and CORS headers - Fix 'Return value from serve handler must be a response' error 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * fix: export app.fetch for ValTown compatibility - Change from 'export default app' to 'export default app.fetch' - Fixes 'Return value from serve handler must be a response' error - GET endpoint now working correctly and returning server info JSON 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * feat: complete import map migration and HTTP endpoint - Remove unused parameter warning in index.http.ts - Add debug logging for request methods - Update .vtignore to include prompts directory for deployment - Complete migration from deno.json import map to direct npm imports - All builds passing and HTTP endpoint working correctly 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * fix: move catch-all handler after specific routes - Move app.all('/*') handler to end of file - Ensures GET and POST handlers are matched before catch-all - Fixes HTTP 405 error for MCP POST requests 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * fix: remove catch-all route causing 405 errors for POST requests The catch-all app.all("/*") route was intercepting POST requests before they could reach the specific POST handler, causing HTTP 405 errors. Removed the unnecessary catch-all as Hono automatically returns 404 for undefined routes and CORS middleware handles OPTIONS. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * docs: update CLAUDE.md with ValTown context and fix repository URLs - Add proper CLAUDE.md header for Claude Code guidance - Include ValTown platform explanation for developers - Document dual deployment architecture (local vs remote) - Fix placeholder repository URLs in README.md and index.http.ts - Add remote server hosting information - Update CHANGELOG.md with documentation improvements 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * fix: address security vulnerabilities in HTTP MCP server - Remove API token logging to prevent credential exposure - Add proper JSON parsing error handling with standard JSON-RPC error codes - Sanitize error responses to prevent information leakage - Update changelog with security fixes 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 22df511 commit ef12c9e

25 files changed

+661
-311
lines changed

.vt/state.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"val": {
3+
"id": "60348fda-486c-11f0-bdd2-76b3cceeab13"
4+
},
5+
"branch": {
6+
"id": "6034f72c-486c-11f0-bdd2-76b3cceeab13",
7+
"version": 54
8+
},
9+
"lastRun": {
10+
"pid": 72741,
11+
"time": "2025-06-14T12:44:10.103Z"
12+
}
13+
}

.vtignore

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
.git
2+
.vscode
3+
.cursorrules
4+
.DS_Store
5+
node_modules
6+
vendor
7+
taskNotes/
8+
README.md
9+
deno.lock
10+
CHANGELOG.md
11+
LICENSE
12+
mcp-documentation.md
13+
mcp.txt
14+
.github
15+
docs
16+
build
17+
taskNotes
18+
valTownApi.json
19+
valtownAPIv2.json
20+
val-town-mcp-server
21+
.claude
22+
mod.ts

CHANGELOG.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,30 @@
44

55
### Added
66

7+
- Added remote HTTP transport for ValTown deployment
8+
- Added GET endpoint for MCP server info
9+
- Added online connection method to README with hosted ValTown server
10+
configuration
711
- Added changelog documentation and guidelines
812
- Added prompt files for Townie and OpenTownie templates with guidelines
913
- Included prompt files in build tasks for all platforms
14+
- Added comprehensive CLAUDE.md with ValTown platform context and architecture overview
1015

1116
### Changed
1217

13-
- Updated README with improved documentation for first-time visitors
18+
- Upgraded to V2 APIs with enhanced prompt system and branch management tools
19+
- Migrated from deno.json import map to direct npm imports
20+
- Updated README with improved documentation for first-time visitors and online
21+
connection method
22+
- Updated CLI function calls to match interface signatures
23+
- Updated Config interface and fixed Deno.run API usage
24+
25+
### Fixed
26+
27+
- Fixed placeholder repository URLs in README.md and index.http.ts documentation links
28+
- Fixed security vulnerability: removed API token logging in HTTP requests
29+
- Fixed missing JSON parse error handling in HTTP MCP endpoint
30+
- Fixed information leakage in HTTP error responses
1431

1532
## [v0.2]
1633

CLAUDE.md

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,43 @@
1-
# ValTown MCP Server Guidelines
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## About ValTown
6+
7+
ValTown is a serverless platform for running TypeScript/JavaScript code in the cloud. Key concepts for developers:
8+
9+
- **Vals**: Code snippets that can be HTTP endpoints, scheduled functions, or scripts
10+
- **HTTP Vals**: Functions that handle HTTP requests (similar to serverless functions)
11+
- **Interval Vals**: Functions that run on a schedule (like cron jobs)
12+
- **Script Vals**: One-time or manually triggered functions
13+
- **Email Vals**: Functions that handle incoming emails
14+
- **API Integration**: Full REST API for programmatic access to create/update/delete vals
15+
- **Remote Execution**: Code runs in ValTown's sandboxed environment with built-in npm package support
16+
17+
## Architecture Overview
18+
19+
This is a Model Context Protocol (MCP) server that provides AI assistants with access to ValTown's platform. The codebase supports two deployment modes:
20+
21+
1. **Local Binary Mode** (`mod.ts`): Runs as a local MCP server using stdio transport
22+
2. **Remote HTTP Mode** (`index.http.ts`): Deployed on ValTown itself as an HTTP endpoint, accessible via streamable HTTP transport
23+
24+
The server is hosted remotely on ValTown at: `https://prashamtrivedi-valtown-mcp-server.val.run/mcp`
25+
26+
Key files:
27+
- `mod.ts`: Local stdio MCP server entry point
28+
- `index.http.ts`: Remote HTTP MCP server entry point (deployed on ValTown)
29+
- `registerTools.ts`: Tool registration with CLI exclusion support for remote deployment
30+
- `config.ts`: Configuration loading with remote/local mode support
231

332
## Commands
4-
- Run server: `deno task start`
33+
34+
- Run server locally: `deno task start`
535
- Development mode: `deno task dev`
636
- Build binaries: `deno task build`
737
- Platform-specific builds: `deno task build:linux`, `deno task build:windows`, `deno task build:macos`
838

939
## Style Guidelines
40+
1041
- Use TypeScript strict mode with explicit typing for function parameters/returns
1142
- 2-space indentation, semicolons at line ends
1243
- Use camelCase for variables/functions, PascalCase for types/interfaces, UPPER_SNAKE_CASE for constants
@@ -16,6 +47,7 @@
1647
- Return consistent error responses with isError flag
1748

1849
## Conventions
50+
1951
- Follow [Conventional Commits](https://www.conventionalcommits.org/) format
2052
- Feature branches: `feature/description`, bug fixes: `fix/description`
2153
- Validate all user inputs and follow least privilege principle

README.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ allows AI assistants to execute code in the ValTown environment.
1414
### Option 1: Use pre-built binaries
1515

1616
Download the appropriate binary for your platform from the
17-
[latest release](https://github.com/YOUR_USERNAME/valtown-mcp-server/releases/latest):
17+
[latest release](https://github.com/PrashamTrivedi/valtown-mcp-server/releases/latest):
1818

1919
- Linux: `valtown-mcp-linux`
2020
- Windows: `valtown-mcp-windows.exe`
@@ -51,6 +51,30 @@ You can obtain a ValTown API token from your
5151

5252
## Usage with MCP Clients
5353

54+
### Online Connection (Hosted on ValTown)
55+
56+
The easiest way to use this MCP server is to connect to the hosted version running on ValTown:
57+
58+
```json
59+
{
60+
"mcpServers": {
61+
"valtown": {
62+
"type": "streamable-http",
63+
"url": "https://prashamtrivedi-valtown-mcp-server.val.run/mcp",
64+
"headers": {
65+
"x-val-town-token": "YOUR_VAL_TOWN_TOKEN_HERE"
66+
}
67+
}
68+
}
69+
}
70+
```
71+
72+
Replace `YOUR_VAL_TOWN_TOKEN_HERE` with your actual ValTown API token.
73+
74+
### Local Installation
75+
76+
If you prefer to run the server locally, you can use the following methods:
77+
5478
### Claude Desktop
5579

5680
#### Windows Configuration

config.ts

Lines changed: 52 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,60 @@
11
import {config as dotenvConfig} from "https://deno.land/x/dotenv@v3.2.2/mod.ts"
22
import * as path from "jsr:@std/path"
33
import {getCliAvailability} from "./lib/vtCli.ts"
4-
export async function loadConfig() {
5-
dotenvConfig({export: true})
4+
export async function loadConfig(remoteMode = false) {
5+
if (remoteMode) {
6+
// For remote: expect token in request headers, use local prompt file
7+
return {
8+
apiToken: null, // Will be set from headers
9+
apiBase: "https://api.val.town",
10+
cli: {
11+
preferCli: false,
12+
path: "vt",
13+
},
14+
prompts: {
15+
valleyPath: `${import.meta.dirname}/prompts/valley.txt`, // Use local file in deployment
16+
defaultValleyPath: `${import.meta.dirname}/prompts/valley.txt`,
17+
},
18+
};
19+
}
620

7-
const API_TOKEN = Deno.env.get("VAL_TOWN_API_TOKEN")
8-
if (!API_TOKEN) {
9-
console.error("Error: VAL_TOWN_API_TOKEN environment variable is required")
10-
Deno.exit(1)
11-
}
21+
// Existing local config logic
22+
dotenvConfig({ export: true });
1223

13-
// CLI preference configuration
14-
const PREFER_CLI = Deno.env.get("VAL_TOWN_PREFER_CLI") !== "false" // Default to true
15-
const CLI_PATH = Deno.env.get("VAL_TOWN_CLI_PATH") || "vt" // Default to "vt" in PATH
16-
// Prompt file paths (can be absolute or relative to CWD)
17-
const VALLEY_PROMPT_PATH = Deno.env.get("VALLEY_PROMPT_PATH")
18-
const useCliIfAvailable = PREFER_CLI ?? false
19-
const cliAvailable = useCliIfAvailable && await getCliAvailability(CLI_PATH)
20-
const defaultPromptPath = `${import.meta.dirname}/prompts/${cliAvailable ? "valley.txt" : "valley_local.txt"}`
24+
const API_TOKEN = Deno.env.get("VAL_TOWN_API_TOKEN");
25+
if (!API_TOKEN) {
26+
console.error("Error: VAL_TOWN_API_TOKEN environment variable is required");
27+
Deno.exit(1);
28+
}
2129

30+
// CLI preference configuration
31+
const PREFER_CLI = Deno.env.get("VAL_TOWN_PREFER_CLI") !== "false"; // Default to true
32+
const CLI_PATH = Deno.env.get("VAL_TOWN_CLI_PATH") || "vt"; // Default to "vt" in PATH
33+
// Prompt file paths (can be absolute or relative to CWD)
34+
const VALLEY_PROMPT_PATH = Deno.env.get("VALLEY_PROMPT_PATH");
35+
const useCliIfAvailable = PREFER_CLI ?? false;
36+
const cliAvailable = useCliIfAvailable && await getCliAvailability();
37+
const defaultPromptPath = `${import.meta.dirname}/prompts/${
38+
cliAvailable ? "valley.txt" : "valley_local.txt"
39+
}`;
2240

23-
// Resolve paths relative to the current working directory if they're not absolute
24-
const resolvedValleyPath = VALLEY_PROMPT_PATH
25-
? (path.isAbsolute(VALLEY_PROMPT_PATH)
26-
? VALLEY_PROMPT_PATH
27-
: defaultPromptPath)
28-
: undefined
29-
return {
30-
apiToken: API_TOKEN,
31-
apiBase: "https://api.val.town",
32-
cli: {
33-
preferCli: PREFER_CLI,
34-
path: CLI_PATH,
35-
},
36-
prompts: {
37-
valleyPath: resolvedValleyPath,
38-
// Default paths included with the binary
39-
defaultValleyPath: defaultPromptPath
40-
}
41-
}
41+
// Resolve paths relative to the current working directory if they're not absolute
42+
const resolvedValleyPath = VALLEY_PROMPT_PATH
43+
? (path.isAbsolute(VALLEY_PROMPT_PATH)
44+
? VALLEY_PROMPT_PATH
45+
: defaultPromptPath)
46+
: undefined;
47+
return {
48+
apiToken: API_TOKEN,
49+
apiBase: "https://api.val.town",
50+
cli: {
51+
preferCli: PREFER_CLI,
52+
path: CLI_PATH,
53+
},
54+
prompts: {
55+
valleyPath: resolvedValleyPath,
56+
// Default paths included with the binary
57+
defaultValleyPath: defaultPromptPath,
58+
},
59+
};
4260
}

deno.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,5 @@
66
"build:linux": "deno compile --output build/valtown-mcp-linux --include prompts/valley.txt --include prompts/valley_local.txt --target x86_64-unknown-linux-gnu --allow-net --allow-env --allow-read mod.ts",
77
"build:windows": "deno compile --output build/valtown-mcp-windows.exe --include prompts/valley.txt --include prompts/valley_local.txt --target x86_64-pc-windows-msvc --allow-net --allow-env --allow-read mod.ts",
88
"build:macos": "deno compile --output build/valtown-mcp-macos --include prompts/valley.txt --include prompts/valley_local.txt --target x86_64-apple-darwin --allow-net --allow-env --allow-read mod.ts"
9-
},
10-
"imports": {
11-
"zod": "npm:zod",
12-
"@modelcontextprotocol/sdk/server": "npm:@modelcontextprotocol/sdk/server",
13-
"@modelcontextprotocol/sdk": "npm:@modelcontextprotocol/sdk"
149
}
1510
}

0 commit comments

Comments
 (0)