-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
docs:(start): add start mcp example #4837
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Balastrong
wants to merge
4
commits into
TanStack:main
Choose a base branch
from
Balastrong:docs/add-start-mcp-example
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
node_modules | ||
package-lock.json | ||
yarn.lock | ||
|
||
.DS_Store | ||
.cache | ||
.env | ||
.vercel | ||
.output | ||
/build/ | ||
/api/ | ||
/server/build | ||
/public/build# Sentry Config File | ||
.env.sentry-build-plugin | ||
/test-results/ | ||
/playwright-report/ | ||
/blob-report/ | ||
/playwright/.cache/ | ||
|
||
count.txt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
**/build | ||
**/public | ||
pnpm-lock.yaml | ||
routeTree.gen.ts |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"servers": { | ||
"start-mcp": { | ||
"type": "http", | ||
"url": "http://localhost:3000/mcp" | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"files.watcherExclude": { | ||
"**/routeTree.gen.ts": true | ||
}, | ||
"search.exclude": { | ||
"**/routeTree.gen.ts": true | ||
}, | ||
"files.readonlyInclude": { | ||
"**/routeTree.gen.ts": true | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# Welcome to TanStack.com! | ||
|
||
This site is built with TanStack Router! | ||
|
||
- [TanStack Router Docs](https://tanstack.com/router) | ||
|
||
It's deployed automagically with Netlify! | ||
|
||
- [Netlify](https://netlify.com/) | ||
|
||
## Development | ||
|
||
From your terminal: | ||
|
||
```sh | ||
pnpm install | ||
pnpm dev | ||
``` | ||
|
||
This starts your app in development mode, rebuilding assets on file changes. | ||
|
||
## Editing and previewing the docs of TanStack projects locally | ||
|
||
The documentations for all TanStack projects except for `React Charts` are hosted on [https://tanstack.com](https://tanstack.com), powered by this TanStack Router app. | ||
In production, the markdown doc pages are fetched from the GitHub repos of the projects, but in development they are read from the local file system. | ||
|
||
Follow these steps if you want to edit the doc pages of a project (in these steps we'll assume it's [`TanStack/form`](https://github.com/tanstack/form)) and preview them locally : | ||
|
||
1. Create a new directory called `tanstack`. | ||
|
||
```sh | ||
mkdir tanstack | ||
``` | ||
|
||
2. Enter the directory and clone this repo and the repo of the project there. | ||
|
||
```sh | ||
cd tanstack | ||
git clone [email protected]:TanStack/tanstack.com.git | ||
git clone [email protected]:TanStack/form.git | ||
``` | ||
|
||
> [!NOTE] | ||
> Your `tanstack` directory should look like this: | ||
> | ||
> ``` | ||
> tanstack/ | ||
> | | ||
> +-- form/ | ||
> | | ||
> +-- tanstack.com/ | ||
> ``` | ||
|
||
> [!WARNING] | ||
> Make sure the name of the directory in your local file system matches the name of the project's repo. For example, `tanstack/form` must be cloned into `form` (this is the default) instead of `some-other-name`, because that way, the doc pages won't be found. | ||
|
||
3. Enter the `tanstack/tanstack.com` directory, install the dependencies and run the app in dev mode: | ||
|
||
```sh | ||
cd tanstack.com | ||
pnpm i | ||
# The app will run on https://localhost:3000 by default | ||
pnpm dev | ||
``` | ||
|
||
4. Now you can visit http://localhost:3000/form/latest/docs/overview in the browser and see the changes you make in `tanstack/form/docs`. | ||
|
||
> [!NOTE] | ||
> The updated pages need to be manually reloaded in the browser. | ||
|
||
> [!WARNING] | ||
> You will need to update the `docs/config.json` file (in the project's repo) if you add a new doc page! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"name": "tanstack-start-example-mcp", | ||
"private": true, | ||
"sideEffects": false, | ||
"type": "module", | ||
"scripts": { | ||
"dev": "vite dev", | ||
"build": "vite build && tsc --noEmit", | ||
"start": "vite start" | ||
}, | ||
"dependencies": { | ||
"@modelcontextprotocol/sdk": "^1.17.0", | ||
"@tanstack/react-router": "^1.130.8", | ||
"@tanstack/react-router-devtools": "^1.130.8", | ||
"@tanstack/react-start": "^1.130.8", | ||
"react": "^19.0.0", | ||
"react-dom": "^19.0.0", | ||
"zod": "3.25.76" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^22.5.4", | ||
"@types/react": "^19.0.8", | ||
"@types/react-dom": "^19.0.3", | ||
"typescript": "^5.7.2", | ||
"vite": "^6.3.5" | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* eslint-disable */ | ||
|
||
// @ts-nocheck | ||
|
||
// noinspection JSUnusedGlobalSymbols | ||
|
||
// This file was automatically generated by TanStack Router. | ||
// You should NOT make any changes in this file as it will be overwritten. | ||
// Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified. | ||
|
||
import { createServerRootRoute } from '@tanstack/react-start/server' | ||
|
||
import { Route as rootRouteImport } from './routes/__root' | ||
import { Route as IndexRouteImport } from './routes/index' | ||
import { ServerRoute as McpServerRouteImport } from './routes/mcp' | ||
|
||
const rootServerRouteImport = createServerRootRoute() | ||
|
||
const IndexRoute = IndexRouteImport.update({ | ||
id: '/', | ||
path: '/', | ||
getParentRoute: () => rootRouteImport, | ||
} as any) | ||
const McpServerRoute = McpServerRouteImport.update({ | ||
id: '/mcp', | ||
path: '/mcp', | ||
getParentRoute: () => rootServerRouteImport, | ||
} as any) | ||
|
||
export interface FileRoutesByFullPath { | ||
'/': typeof IndexRoute | ||
} | ||
export interface FileRoutesByTo { | ||
'/': typeof IndexRoute | ||
} | ||
export interface FileRoutesById { | ||
__root__: typeof rootRouteImport | ||
'/': typeof IndexRoute | ||
} | ||
export interface FileRouteTypes { | ||
fileRoutesByFullPath: FileRoutesByFullPath | ||
fullPaths: '/' | ||
fileRoutesByTo: FileRoutesByTo | ||
to: '/' | ||
id: '__root__' | '/' | ||
fileRoutesById: FileRoutesById | ||
} | ||
export interface RootRouteChildren { | ||
IndexRoute: typeof IndexRoute | ||
} | ||
export interface FileServerRoutesByFullPath { | ||
'/mcp': typeof McpServerRoute | ||
} | ||
export interface FileServerRoutesByTo { | ||
'/mcp': typeof McpServerRoute | ||
} | ||
export interface FileServerRoutesById { | ||
__root__: typeof rootServerRouteImport | ||
'/mcp': typeof McpServerRoute | ||
} | ||
export interface FileServerRouteTypes { | ||
fileServerRoutesByFullPath: FileServerRoutesByFullPath | ||
fullPaths: '/mcp' | ||
fileServerRoutesByTo: FileServerRoutesByTo | ||
to: '/mcp' | ||
id: '__root__' | '/mcp' | ||
fileServerRoutesById: FileServerRoutesById | ||
} | ||
export interface RootServerRouteChildren { | ||
McpServerRoute: typeof McpServerRoute | ||
} | ||
|
||
declare module '@tanstack/react-router' { | ||
interface FileRoutesByPath { | ||
'/': { | ||
id: '/' | ||
path: '/' | ||
fullPath: '/' | ||
preLoaderRoute: typeof IndexRouteImport | ||
parentRoute: typeof rootRouteImport | ||
} | ||
} | ||
} | ||
declare module '@tanstack/react-start/server' { | ||
interface ServerFileRoutesByPath { | ||
'/mcp': { | ||
id: '/mcp' | ||
path: '/mcp' | ||
fullPath: '/mcp' | ||
preLoaderRoute: typeof McpServerRouteImport | ||
parentRoute: typeof rootServerRouteImport | ||
} | ||
} | ||
} | ||
|
||
const rootRouteChildren: RootRouteChildren = { | ||
IndexRoute: IndexRoute, | ||
} | ||
export const routeTree = rootRouteImport | ||
._addFileChildren(rootRouteChildren) | ||
._addFileTypes<FileRouteTypes>() | ||
const rootServerRouteChildren: RootServerRouteChildren = { | ||
McpServerRoute: McpServerRoute, | ||
} | ||
export const serverRouteTree = rootServerRouteImport | ||
._addFileChildren(rootServerRouteChildren) | ||
._addFileTypes<FileServerRouteTypes>() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { createRouter as createTanStackRouter } from '@tanstack/react-router' | ||
import { routeTree } from './routeTree.gen' | ||
|
||
export function createRouter() { | ||
const router = createTanStackRouter({ | ||
routeTree, | ||
scrollRestoration: true, | ||
}) | ||
|
||
return router | ||
} | ||
|
||
declare module '@tanstack/react-router' { | ||
interface Register { | ||
router: ReturnType<typeof createRouter> | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import * as React from 'react' | ||
import { HeadContent, Scripts, createRootRoute } from '@tanstack/react-router' | ||
import { TanStackRouterDevtools } from '@tanstack/react-router-devtools' | ||
|
||
export const Route = createRootRoute({ | ||
head: () => ({ | ||
meta: [ | ||
{ | ||
charSet: 'utf-8', | ||
}, | ||
{ | ||
name: 'viewport', | ||
content: 'width=device-width, initial-scale=1', | ||
}, | ||
{ | ||
title: 'TanStack Start MCP Starter', | ||
}, | ||
], | ||
}), | ||
shellComponent: RootDocument, | ||
}) | ||
|
||
function RootDocument({ children }: { children: React.ReactNode }) { | ||
return ( | ||
<html> | ||
<head> | ||
<HeadContent /> | ||
</head> | ||
<body> | ||
{children} | ||
<TanStackRouterDevtools position="bottom-right" /> | ||
<Scripts /> | ||
</body> | ||
</html> | ||
) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import * as fs from 'node:fs' | ||
import { createFileRoute, useRouter } from '@tanstack/react-router' | ||
import { createServerFn } from '@tanstack/react-start' | ||
|
||
const filePath = 'count.txt' | ||
|
||
async function readCount() { | ||
return parseInt( | ||
await fs.promises.readFile(filePath, 'utf-8').catch(() => '0'), | ||
) | ||
} | ||
|
||
export const getCount = createServerFn({ method: 'GET' }).handler(() => { | ||
return readCount() | ||
}) | ||
|
||
const updateCount = createServerFn({ method: 'POST' }) | ||
.validator((addBy: number) => addBy) | ||
.handler(async ({ data }) => { | ||
const count = await readCount() | ||
await fs.promises.writeFile(filePath, `${count + data}`) | ||
}) | ||
|
||
export const Route = createFileRoute('/')({ | ||
component: Home, | ||
loader: async () => await getCount(), | ||
}) | ||
|
||
function Home() { | ||
const router = useRouter() | ||
const state = Route.useLoaderData() | ||
|
||
return ( | ||
<button | ||
onClick={() => { | ||
updateCount({ data: 1 }).then(() => { | ||
router.invalidate() | ||
}) | ||
}} | ||
> | ||
Add 1 to {state}? | ||
</button> | ||
) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vite start
wont work I guess?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I copied from the
start-counter
example but I haven't tried before. I did now and... yeahvite start
doesn't seem to work.Should we replace all
vite start
withnode .output/server/index.mjs
in the examples?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well it depends on the deployment target. by default, it's using node, so yes it would work. if someone changes to e.g. bun, the start command would need to be different ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it something related to this PR (adding the new mcp example) only or is it a global decision for all
start
commands in all examples/docs?I'd say as long as we explain in the docs how to run in all environments should be fine that we show one in the feature-related examples