Skip to content

Instantly share code, notes, and snippets.

View kevinswiber's full-sized avatar
🍄
lizard person

Kevin Swiber kevinswiber

🍄
lizard person
View GitHub Profile
@kevinswiber
kevinswiber / server.js
Last active December 25, 2025 23:54
Node.js server with best-effort completions on functions
import { AsyncResource } from "node:async_hooks";
import { createServer, request } from "node:http";
// A thin wrapper around AsyncResource to manage best-effort completions.
// Best-effort resources are not guaranteed to complete, but they are
// allowed time to complete before the process exits on SIGINT.
// In a real-world scenario, you would likely include more details
// in the resource context to help trace completed and
// abandoned best-effort executions.
class BestEffort extends AsyncResource {
@kevinswiber
kevinswiber / backends.js
Last active December 10, 2025 00:17
Express Gateway Example with Multiple Services
const express = require('express');
const forum = express();
forum
.get('/healthz', (req, res, next) => {
res.send({ name: 'forum', status: 'healthy' });
next();
})
.get('/d/:id', (req, res, next) => {

Questions about MCP Tasks

1. Authorization Context Scope

The Tasks specification (2025-11-25) introduces "authorization context" for task binding and access control. However, other stateful protocol elements—initialization/capability negotiation, progress tokens, sampling requests, roots—also require context binding in multi-tenant deployments.

Was the decision to scope authorization context to Tasks intentional, or would you consider elevating it to a protocol-wide concept?


@kevinswiber
kevinswiber / Program.cs
Created November 23, 2011 23:05
Passing messages between Node.js and C#.
using System;
using System.Text;
namespace NodeIPC
{
class Program
{
static void Main(string[] args)
{
var input = Console.OpenStandardInput();
@kevinswiber
kevinswiber / typescript-hook.js
Last active November 27, 2023 15:15
Run the TypeScript compiler in watch mode while running Node.js in watch mode. Yowza.
// Usage:
// node --import=./typescript-hook.js --watch ./dist/index.js
//
// Make changes to your TypeScript code, have it automatically
// recompiled, and see it reloaded in Node.js.
//
// This file is intended to be used as a Node.js preload module.
// The TypeScript compiler (tsc) will be run in watch mode.
// This is useful while running Node.js itself runs in watch mode.
//
@kevinswiber
kevinswiber / url-pattern.js
Last active October 24, 2023 21:04
Implementation of URL Pattern spec
import assert from "node:assert";
function escapeRegexString(str) {
return str.replace(/[\.\+\*\?\^\$\{\}\(\)\[\]\|\/\\]/g, "\\$&");
}
function isValidNameCodePoint(codePoint, isFirstCodePoint) {
if (isFirstCodePoint) {
return (codePoint >= 65 && codePoint <= 90) ||
(codePoint >= 97 && codePoint <= 122) ||
@kevinswiber
kevinswiber / http-server.js
Last active October 19, 2023 21:49
Simple Node.js HTTP server with router and logging.
// Purpose: A simple HTTP server with routing and logging.
// Author: Kevin Swiber <kswiber@gmail.com>
// Exports:
// serve({ routes, host, port, protocol, secure, serverOptions })
// routes: A Map of routes to handlers. Example:
// const routes = new Map();
// routes.set("/greeting", {
// get: ({ response }) => {
// response.setHeader("Content-Type", "application/json");
// response.end(JSON.stringify({ hello: "world" }));
@kevinswiber
kevinswiber / .spectral.yaml
Created October 13, 2023 05:01
Spectral de-dupe minimal repro
rules:
missing_error_response_content:
given: '$..responses[?(@property && @property.match(/^(4|5)/))]'
then:
field: content
function: defined
formats:
- oas3
severity: warn
message: Error response should contain a response body.
@kevinswiber
kevinswiber / postman-external-require-browserify-cdn.js
Last active October 7, 2023 20:47
Postman pre-request script to set init and cleanup environment variables that pull down browserify bundles from the browserify service.
/*
This is a pre-request script for Postman collections, folders, or requests that imports
packages from npm after bundling them through [Browserify-CDN](https://wzrd.in/).
## Usage
In global, collection, or environment variables, define a variable named `dependencies`
that lists packages to import in the form `<package-name>@<version>`. To include
multiple packages, separate the package specs with commas
(e.g., `async@latest,debug@4.1.1`).
@kevinswiber
kevinswiber / extensions.json
Last active September 26, 2023 19:39
Spectral JSON Schema
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "@stoplight/spectral-core/meta/extensions",
"$defs": {
"Extends": {
"$anchor": "extends",
"oneOf": [
{
"type": "string"
},