File tree Expand file tree Collapse file tree 2 files changed +18
-7
lines changed Expand file tree Collapse file tree 2 files changed +18
-7
lines changed Original file line number Diff line number Diff line change 1+ import { randomUUID } from "crypto" ;
2+
13const BASE_URL = "https://buildwithfern.com/learn" ;
4+ const X_FERN_HOST = "buildwithfern.com" ;
25
36export async function postChat ( message : string ) {
47 const response = await fetch ( `${ BASE_URL } /api/fern-docs/search/v2/chat` , {
58 method : "POST" ,
69 headers : {
710 "content-type" : "application/json" ,
11+ "x-fern-host" : X_FERN_HOST ,
812 } ,
913 body : JSON . stringify ( {
10- messages : [ { role : "user" , content : message } ] ,
11- url : "https://buildwithfern.com/learn" ,
12- filters : [ ] ,
14+ messages : [ { role : "user" , parts : [ { type : "text" , text : message } ] } ] ,
15+ conversationId : randomUUID ( ) ,
16+ url : BASE_URL ,
1317 } ) ,
1418 } ) ;
1519
Original file line number Diff line number Diff line change @@ -25,10 +25,17 @@ export function registerMcpTools(server: McpServer) {
2525 "Ask Fern AI about anything related to Fern." ,
2626 { message : z . string ( ) } ,
2727 async ( { message } ) => {
28- const result = await api . postChat ( message ) ;
29- return {
30- content : [ { type : "text" , text : result } ] ,
31- } ;
28+ try {
29+ const result = await api . postChat ( message ) ;
30+ return {
31+ content : [ { type : "text" , text : result } ] ,
32+ } ;
33+ } catch ( error ) {
34+ return {
35+ content : [ { type : "text" , text : "[ERROR] " + error . message } ] ,
36+ isError : true ,
37+ } ;
38+ }
3239 }
3340 ) ;
3441}
You can’t perform that action at this time.
0 commit comments