SpringAi-mcp高德

1.创建key

进入高德官网注册,创建key

https://console.amap.com/dev/id/phone(官网)

2.编写yml文件

引入自己的key

复制代码
#高德的key
AMAP-KEY: #自己的key,复制上

3.创建工具类

3.1AmapService

java 复制代码
package com.jiazhong.mingxing.ai.siliconflow.mcp.glm.service;

import org.springframework.stereotype.Service;

@Service
public interface AmapSrvice {
    String weatherAmap(String city);
}

3.2Impl类

java 复制代码
package com.jiazhong.mingxing.ai.siliconflow.mcp.glm.service.impl;

import com.jiazhong.mingxing.ai.siliconflow.mcp.glm.service.AmapSrvice;
import jakarta.annotation.Resource;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.ai.tool.annotation.ToolParam;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class AmapServiceImpl implements AmapSrvice {
    @Resource
    private RestTemplate restTemplate;

    @Value("${AMAP-KEY}")
    private String key;
    @Tool(description = "根据城市获取到具体天气情况")
    public String weatherAmap(@ToolParam(description = "具体的城市名称") String city) {
        String url="https://restapi.amap.com/v3/weather/weatherInfo?key="+
                key + "&city=" + city + "&extensions=all";
        return restTemplate.getForObject(url,String.class);
    }
}

4.注册工具类

java 复制代码
@Configuration
public class ChatClientConfig {
    /*@Resource
    private OpenAiChatModel openAiChatModel;
    @Resource
    private NowDateToolService nowDateToolService;
    @Resource
    private WeatherJiaService weatherJiaService;*/
    @Resource
    private AmapSrvice amapService;
    @Bean("openAiChatClient")
    public ChatClient openAiChatClient(OpenAiChatModel openAiChatModel){
       /* FunctionToolCallback<Weather.WeatherRequest,Weather.WeatherResponse> toolCallback
                =FunctionToolCallback.builder("weatherJiaServiceImpl",weatherJiaService)
                .description("获取到执行位置的天气").inputType(Weather.WeatherRequest.class).build();*/
        return ChatClient.builder(openAiChatModel)
                /*.defaultTools(currentWeather)*/
                /*.defaultToolNames("currentWeather","currentDressing")*/
                .defaultTools(amapService)
                .build();
    }
}
相关推荐
Maddie_Mo1 小时前
Unity 联动 Trae AI 项目开发基础教学
人工智能·unity·游戏引擎
光锥智能1 小时前
Google 与百度同步布局智能体:AI 竞争进入全栈能力比拼阶段
人工智能·百度
一点一木7 小时前
深度体验TRAE SOLO移动端7天:作为独立开发者,我把工作流揣进了兜里
前端·人工智能·trae
Lee川8 小时前
mini-cursor 揭秘:从 Tool 定义到 Agent 循环的完整实现
前端·人工智能·后端
weelinking8 小时前
【产品】00_产品经理用Claude实现产品系列介绍
数据库·人工智能·sql·数据挖掘·github·产品经理
Agent产品评测局8 小时前
制造业模具管理AI系统,主流产品能力对比详解:2026年智能制造选型深度洞察
人工智能·ai·chatgpt·制造
研华科技Advantech9 小时前
如何用一套实训设备,打通工业AI预测性维护技术全流程?
人工智能
Lab_AI9 小时前
AI for Science: MaXFlow AI Agent+ 报告体验双升级,让AI智能体更高效易用!
人工智能·ai for science·ai agent·ai智能体
李坤9 小时前
让 Codex 和 Claude 互相 Review:告别手动复制
人工智能·openai·claude
南屹川9 小时前
【API设计】GraphQL实战:从REST到GraphQL的演进
人工智能