Val Town Code SearchReturn to Val Town

API Access

You can access search results via JSON API by adding format=json to your query:

https://codesearch.val.run/?q=function&page=47&format=json

For typeahead suggestions, use the /typeahead endpoint:

https://codesearch.val.run/typeahead?q=function

Returns an array of strings in format "username" or "username/projectName"

Found 30868 results for "function"(1521ms)

val-town-http-mcp-servertownie.txt17 matches

@nbbaierโ€ขUpdated 2 days ago
10 1. `http`: http vals export a default server request handler.
11 2. `script`: script vals can be imported into other vals, similar to an npm package.
12 3. `cron`: cron vals export a function that can automatically run at user-set intervals, similar to a cron command.
13 4. `email`: email vals export a function that runs when its associated email address receives an email.
14
15Follow these requirements for Val Town when generating code.
49</requirements>
50
51If the user asks for specific functionality, the Val Town standard library includes the following:
52
53<libraries>
63 ```
64
65 Blob storage only works on the server. If the val includes client-side code, use dynamic imports to import this module in the server function, e.g.:
66 `const { blob } = await import("https://esm.town/v/std/blob");`
67 </library>
78 If you are changing a SQLite table's schema, you should also change the table's name so it creates a fresh table, ie by adding _2 or _3 after it everywhere. Ensure that tables are created before they are used.
79
80 SQLite storage only works on the server. If the val includes client-side code, use dynamic imports to import this module in the server function, e.g.:
81 `const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");`
82 </library>
99 ```
100
101 OpenAI only works on the server. If the val includes client-side code, use dynamic imports to import this module in the server function, e.g.:
102 `const { OpenAI } = await import "https://esm.town/v/std/openai");`
103 </library>
113 ```
114
115 Email only works on the server. If the val includes client-side code, use dynamic imports to import this module in the server function, e.g.:
116 `const { email } = await import "https://esm.town/v/std/email");`
117 </library>
131 Write the code in ```val code fences.
132 Include the val type as metadata on the code fence, e.g.: ```val type=script
133 If this is a new val, decide what val type is appropriate based on the user's prompt. Default to choosing http type vals unless the user has requested specific functionality that requires a different type.
134
135 * If the user requests diff format in their prompt, follow these steps:
157 * Use fetch to communicate with the backend server portion.
158 */
159function App() {
160 return (
161 <div>
167/**
168 * Client-only code
169 * Any code that makes use of document or window should be scoped to the `client()` function.
170 * This val should not cause errors when imported as a module in a browser.
171 */
172function client() {
173 createRoot(document.getElementById("root")).render(<App />);
174}
177/**
178 * Server-only code
179 * Any code that is meant to run on the server should be included in the server function.
180 * This can include endpoints that the client side component can send fetch requests to.
181 */
182export default async function server(request: Request): Promise<Response> {
183 /** If needed, blob storage or sqlite can be imported as a dynamic import in this function.
184 * Blob storage should never be used in the browser directly.
185 * Other server-side specific modules can be imported in a similar way.
232 ```val type=script
233 /** Use this template for creating script vals only */
234 export default function () {
235 return "Hello, world";
236 }
243 ```val type=cron
244 /** Use this template for creating cron vals only */
245 export default async function (interval: Interval) {
246 // code will run at an interval set by the user
247 console.log(`Hello, world: ${Date.now()}`);
270 // The email address for this val will be `<username>.<valname>@valtown.email` which can be derived from:
271 // const emailAddress = new URL(import.meta.url).pathname.split("/").slice(-2).join(".") + "@valtown.email";
272 export default async function (e: Email) {
273 console.log("Email received!", email.from, email.subject, email.text);
274 }

val-town-http-mcp-serversqliteTools.ts3 matches

@nbbaierโ€ขUpdated 2 days ago
5import {getErrorMessage} from "../lib/errorUtils.ts"
6
7export function registerSqliteTools(server: McpServer, config: Config) {
8 // Execute SQL
9 server.tool(
64 )
65
66 // Fix for sqlite-query function
67 server.tool(
68 "sqlite-query",
91 )
92
93 // Fix for sqlite-exec function
94 server.tool(
95 "sqlite-exec",

val-town-http-mcp-serverregisterTools.ts2 matches

@nbbaierโ€ขUpdated 2 days ago
11import {registerPrompts} from "./prompts/promptsTools.ts"
12
13export function registerTools(
14 server: McpServer,
15 config: Config,
29}
30
31export function registerPromptsTools(server: McpServer, config: Config) {
32 registerPrompts(server, config)
33}

val-town-http-mcp-serverpromptsTools.ts1 match

@nbbaierโ€ขUpdated 2 days ago
8
9// Register prompt capabilities with server
10export function registerPrompts(server: McpServer, _config: Config) {
11 // Townie prompt
12 server.prompt(

val-town-http-mcp-serverprojectTools.ts1 match

@nbbaierโ€ขUpdated 2 days ago
5import {getCliAvailability, runVtCommand} from "../lib/vtCli.ts"
6
7export function registerProjectTools(server: McpServer, config: Config) {
8 // List all projects
9 server.tool(

val-town-http-mcp-serveropentownie.txt9 matches

@nbbaierโ€ขUpdated 2 days ago
23- Respond in a friendly and concise manner
24- Ask clarifying questions when requirements are ambiguous
25- Provide complete, functional solutions rather than skeleton implementations
26- Test your logic against edge cases before presenting the final solution
27- Ensure all code follows Val Town's specific platform requirements
36- **Never bake in secrets into the code** - always use environment variables
37- Include comments explaining complex logic (avoid commenting obvious operations)
38- Follow modern ES6+ conventions and functional programming practices where appropriate
39
40### Val Town Utility Functions
41
42Val Town provides several utility functions to help with common project tasks. These utilities handle file management, project information, and testing.
43
44### Importing Utilities
90 {
91 name: "should add numbers correctly",
92 function: () => {
93 expect(1 + 1).toBe(2);
94 },
174โ”‚ โ”œโ”€โ”€ database/
175โ”‚ โ”‚ โ”œโ”€โ”€ migrations.ts # Schema definitions
176โ”‚ โ”‚ โ”œโ”€โ”€ queries.ts # DB query functions
177โ”‚ โ”‚ โ””โ”€โ”€ README.md
178โ”‚ โ”œโ”€โ”€ index.ts # Main entry point
190โ””โ”€โ”€ shared/
191 โ”œโ”€โ”€ README.md
192 โ””โ”€โ”€ utils.ts # Shared types and functions
193```
194
196- Hono is the recommended API framework (similar to Express, Flask, or Sinatra)
197- Main entry point should be `backend/index.ts`
198- **Static asset serving:** Use the utility functions to read and serve project files:
199 ```ts
200 // Use the serveFile utility to handle content types automatically
237- Run migrations on startup or comment out for performance
238- Change table names when modifying schemas rather than altering
239- Export clear query functions with proper TypeScript typing
240- Follow the queries and migrations pattern from the example
241

val-town-http-mcp-serverindex.http.ts1 match

@nbbaierโ€ขUpdated 2 days ago
3 *
4 * This is the HTTP entry point for the ValTown MCP Server when deployed
5 * on ValTown itself. It excludes CLI-dependent functionality and uses
6 * header-based authentication with Hono and StreamableHTTPServerTransport.
7 */

val-town-http-mcp-serverfileTools.ts2 matches

@nbbaierโ€ขUpdated 2 days ago
16 * 5. Clean up workspace
17 */
18async function performFileOperationWithCli(
19 config: Config,
20 valId: string,
88}
89
90export function registerFileTools(server: McpServer, config: Config) {
91 // List files in a val branch
92 server.tool(

val-town-http-mcp-servererrorUtils.ts1 match

@nbbaierโ€ขUpdated 2 days ago
4 * @returns A string representation of the error
5 */
6export function getErrorMessage(error: unknown): string {
7 if (error instanceof Error) {
8 return error.message

val-town-http-mcp-serverconfig.ts1 match

@nbbaierโ€ขUpdated 2 days ago
2import * as path from "jsr:@std/path"
3import {getCliAvailability} from "./lib/vtCli.ts"
4export async function loadConfig(remoteMode = false) {
5 if (remoteMode) {
6 // For remote: expect token in request headers, use local prompt file
tuna

tuna9 file matches

@jxnblkโ€ขUpdated 1 week ago
Simple functional CSS library for Val Town

getFileEmail4 file matches

@shouserโ€ขUpdated 1 month ago
A helper function to build a file's email
lost1991
import { OpenAI } from "https://esm.town/v/std/openai"; export default async function(req: Request): Promise<Response> { if (req.method === "OPTIONS") { return new Response(null, { headers: { "Access-Control-Allow-Origin": "*",
webup
LangChain (https://langchain.com) Ambassador, KubeSphere (https://kubesphere.io) Ambassador, CNCF OpenFunction (https://openfunction.dev) TOC Member.